akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;

int main(void){
    int n, a[100], v, j, i, k;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for (k = 0; k < n; k++){
            if (k < n-1) printf("%d ", a[k]);
            else printf("%d", a[k]);
        }
        printf("\n");
    for (i = 1; i < n; i++){
        v = a[i];
        j = i -1;
        while (j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
            a[j+1] = v;
        }
        for (k = 0; k < n; k++){
            if (k < n-1) printf("%d ", a[k]);
            else printf("%d", a[k]);
        }
        printf("\n");
    }
    
    return 0;
}

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

int main(int argc, const char * argv[]) {
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, times;
    
    cin >> a >> b;
    times = a*b;
    if(times%2)
        cout << "Odd" << endl;
    else
        cout << "Even" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n;
    cin >> n;
    set<int> st;
    rep(i, n) {
        int a;
        cin >> a;
        st.insert(a);
    }
    if(n != st.size()) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12928
using System;
using System.Collections.Generic;

public class Fenec {
  public static void Main(string[] args) {
    string[] str1 = Console.ReadLine().Split();
    var h = int.Parse(str1[0]);
    var k = int.Parse(str1[1]);
    long sum = 0;
    
    string[] str2 = Console.ReadLine().Split();
    var list = new List<int>();
    for (var i = 0; i < h; i++) {
      list.Add(int.Parse(str2[i]));
    }
    
    list.Sort((a, b) => b - a);
    
    for (var i = 0; i < (h - k); i++) {
      sum += list[k+i];
    }
    
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 33084
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,x,i,cou=0,n,cou2=0,j;
  
  cin >> N >> x;
  vector<int> a(N);
  for(i=0;i<N;i++){
  cin >> a.at(i);
  }
  std::sort(a.begin(), a.end() );
  for(i=0;i<N;i++){
    n=x;
    cou=0;
  	for(j=i;j<N;j++){
      if(j==N-1){
        if(a.at(j)==n){
        cou++;
        }
      }else{
    	if(a.at(j)<=n){
    	  cou++;
          n-=a.at(j);
    	}
      }
    }
    if(cou2<cou){
      cou2=cou;
    }
  }
  cout << cou2 << endl;
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  string u,d; cin >> u >> d;
  
  ll ans = 1;
  for (int i = 0; i < N;) {
    if (u[i] == d[i]) {
     if (i == 0) ans *= 3;
     else {
       if (u[i-1] == d[i-1]) ans = ans * 2 % MOD;
     }
     i++;
    } else {
      if (i == 0) ans *= 6;
      else {
        if (u[i-1] == d[i-1]) ans = ans * 2 % MOD;
        else ans = ans * 3 % MOD;
      }
      i += 2;
    }
  }

  cout << ans << endl;
}

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

#define ll long long

using namespace std;

const int maxn=1e5+10;
string s[maxn];
long long n;
long long  ans=0;
int main(){
    cin >>n;
    for(int i=0;i<n;i++){
        cin >>s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s,s+n);
    long long cnt=1;
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]){
            cnt++;
        }else{
            ans+=(cnt*(cnt-1))/2;
            cnt=1;
        }
        if(i==n-1) ans+=(cnt*(cnt-1))/2;
    }
    cout << ans <<endl;
  //  system("pause");
    return 0;
}

Measured memory_bytes: 9344
#include <iostream>
#include <vector>
using namespace std;
int main () {
	int n,s;
	s=0;
	cin>>n;
	vector<int> d(n);
	for(int i=0;i<n;i++){
		cin>>d[i];
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			s+=(d[i]*d[j]);
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int n,a[N],minn = 1000000000,pos,ans;
int k;
int main()
{
    scanf("%d%d",&n,&k);
    if(n == k){cout<<"1"<<endl;return 0;}
    for(int  i = 1;i <= n; i++){
       scanf("%d",&a[i]);
       if(a[i] < minn) {
       minn = a[i];
       pos = i;
       }
    }
    
    ans++;int l,r,len;l = r = pos;len = k - 1;
   
    while(l > 1 && len) l--,len--;
    while(r < n && len) r++,len--;
     
    if(r < n && l >1)r++,l++;
    //cout<<l<<" "<<r<<endl;
    if(r < n && (n - r)%(k-1) != 0)ans++;
    if(l > 1 && (l - 1)%(k-1) != 0)ans++;
   
   
   // cout<<ans<<endl;
    ans +=  (n - r)/(k - 1);
    ans +=  (l - 1)/(k - 1);
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
h=[]
for i in range(n):
  h_=int(input())
  h.append(h_)
  
h.sort()

ans=float('inf')
for i in range(1,n-k+2):
  ans=min(ans,h[n-i]-h[n-i-k+1])
  
print(ans)

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

int main() {
  int n, sum=0;
  cin >> n;
  vector<int> d(n);
  for(int i = 0;i<n;i++){
    cin >> d.at(i);
  }
  for(int i = 0;i < n - 1;i++){
    for(int j = i+1;j<n;j++){
    	sum = sum + d.at(i)*d.at(j);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
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; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)



signed main(){
    cout << fixed << setprecision(10);
    intl x, k, d;
    cin >> x >> k >> d;
    if(x < 0)x *= -1;
    intl num = x / d;
    if(k <= num){
        cout << abs(x - (k * d)) << endl;
        return 0;
    }
    intl a = x - num * d;
    intl k0 = k - num;
    if(k0 % 2){
        a -= d;
        cout << abs(a) << endl;
        return 0;
    }
    else {
        cout << abs(a) << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

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

int main(void){
    int H, W; cin >> H >> W;
    vector<string> G(H);
    for(int i = 0; i < H; i++){
        cin >> G[i];
    }
    
    queue<pair<int, int>> que;
    vector<vector<int>> dis(H, vector<int>(W, -1));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(G[i][j] == '#') que.push(make_pair(i, j));
            dis[i][j] = 0;
        }
    }
    
    while(!que.empty()){
        pair<int, int> p = que.front(); que.pop();
        int h = p.first, w = p.second;
            for(int i = 0; i < 4; i++){
                int nh = h + dx[i];
                int nw = w + dy[i];
                
                if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
                
                if(G[nh][nw] == '.'){
                    G[nh][nw] = '#';
                    dis[nh][nw] = dis[h][w] + 1;
                    que.push(make_pair(nh, nw));
            }
        }
    }
    
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            ans = max(ans, dis[i][j]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 13456
#include<stdio.h>
int LinearSearch(int,int,int);

int main(){
  int n,q,i,key,result=0;
  int s[10000+1];

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&key);//配列tのi番目の値をkeyとしてsのi番目?最後までの値と比較する
    if(LinerSearch(s,n,key)!=0) result++;
  }
  printf("%d\n",result);
  return 0;
}

int LinerSearch(int s[],int n,int key){
  int i=0;
  s[n]=key;
  while(s[i]!=key){
    i++;
  }
  if(i==n){
    return 0;
  }
  return 1;//iとnが同値でないときiをreturnし、同値なとき0をreturnする。nは番兵なのでi=nになってはいけない
}

  




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

int main(){
    string name[3];
    bool copy=false;
    int i;
    for(int i=0;i<3;i++) cin >> name[i];
    for(int i=0;i<3;i++) cout << name[i].at(0);
    cout << endl;
    return 0;
}


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

using namespace std;

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

uint64_t gcd(uint64_t a, uint64_t b){
  return a ? gcd(b % a, a) : b;
}

int main(){
  uint64_t a, b;
  cin >> a >> b;
  cout << a * b / gcd(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
S = input()

numW = [0]*N
numE = [0]*N
tmpW = 0
tmpE = 0
for i,s in enumerate(S):
    if s == 'W':
        tmpW += 1
    else:
        tmpE += 1

    numW[i] = tmpW
    numE[i] = tmpE

npans = np.zeros(N,dtype = int)
npans[0] = numE[-1] - numE[0]
for i in range(1,N):
    npans[i] = numW[i-1] + numE[-1] - numE[i]
print(np.min(npans))


# npans = np.zeros(N,dtype = int)
# for i,s in enumerate(S):
#     if s == 'W':
#         npans[i+1:] += 1
#     else:
#         npans[:i] += 1
# print(np.min(npans))


Measured memory_bytes: 28864
#include <bits/stdc++.h>
using namespace std;
#define int long long

int solve(int x)
{
    if(x & 1) return 0;
    int ans = x / 10;
    x /= 10;
    while(x >= 5)
    {
        ans += (x / 5);
        x /= 5;
    }
    return ans;
}

int32_t main()
{
    int n;
    cin >> n;
    cout << solve(n) << '\n';
 
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	m := getNextInt(scanner)
	var dsum, csum int64
	for i := 0; i < m; i++ {
		d := getNextInt64(scanner)
		c := getNextInt64(scanner)
		dsum += d * c
		csum += c
	}

	fmt.Fprintln(writer, csum+(dsum-1)/9-1)
	writer.Flush()
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	fmt.Scanf("%f", &x)
	var result = 0.0
	tmp := math.Floor(x / 500)
	result += tmp * 1000
	x -= 500 * tmp
	tmp = math.Floor(x / 5)
	result += tmp * 5

	fmt.Println(int(result))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
ll dp[20][2][6];	//d,just=1,type	5 = ok

int main(){
	string s;
	cin>>s;
	int N = s.size();
	dp[0][1][0] = 1;
	rep(i,N) rep(just,2) rep(t,6){
		rep(c,10){
			if(just && c>s[i]-'0') break;
			int ni = i+1;
			int njust = (just && c==s[i]-'0');
			int nt = 0;
			if(t==0 && c==5) nt = 1;
			else if(t==1 && c==1) nt = 2;
			else if(t==2 && c==5) nt = 3;
			else if(t==2 && c!=5) nt = 4;
			else if(t==3 && c==3) nt = 5;
			else if(t==4 && c==3) nt = 5;
			else if(t==5) nt = 5;
			else{
				if(t==3 && c==1) nt = 2;
				if(c==5) nt = 1;
			}
			dp[ni][njust][nt] += dp[i][just][t];
		}
	}
	cout<<dp[N][0][5]+dp[N][1][5]<<endl;
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007


int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k;
    cin>>n>>k;
    int a[n],s[k+1],dp[k+1];
    for(int i=0;i<n;i++)cin>>a[i];
    s[0]=1;dp[0]=1;
    for(int j=1;j<=k;j++)
    {
        if(j<=a[0])dp[j]=1;
        else dp[j]=0;
        s[j]=s[j-1]+dp[j];
    }
    
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(j<=a[i])dp[j]=s[j]%mod;
            else dp[j]=(s[j]-s[j-a[i]-1])%mod;
            
            if(dp[j]<0)dp[j]+=mod;
        }
        for(int j=1;j<=k;j++)
        {
            s[j]=(s[j-1]+dp[j])%mod;
        }
    }
    cout<<dp[k]<<"\n";
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

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

  ull result = 0;

  each(i, 3) {
    if (s[i] == t[i])
      result++;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	cout << 2 * r * PI << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

bool dfs(vi a){
  // DEBUG_VEC(a);
  int sum = 0;
  REPR(i,10)sum+=a[i];
  if(sum==0)return true;
  if(sum%3!=0)assert(false&&"?????????????????????????????????");
  // ????????????
  REPR(i,10-2){
    if(a[i]>0 && a[i+1]>0 && a[i+2]>0){
      vi b = a;
      b[i]--;
      b[i+1]--;
      b[i+2]--;
      if(dfs(b))return true;
    }
  }
  // ??????
  REPR(i,10){
    if(a[i]>=3){
      vi b = a;
      b[i]-=3;
      if(dfs(b))return true;
    }
  }
  return false;
}

int main(){
  ll pi;
  while(~scanf("%lld",&pi)){
    vi res;
    vi picnt(10,0);
    REP(i,13){
      picnt[pi%10]++;
      pi/=10;
    }
    // DEBUG_VEC(picnt);
    // ???????????????
    REPR(i,10){
      bool flag = false;
      if(picnt[i]==4)continue;
      ++picnt[i];
      // ??????????????????
      REPR(j,10){
        if(picnt[j]<2)continue;
        picnt[j]-=2;
        bool ok = dfs(picnt);
        picnt[j]+=2;
        if(ok){
          flag = true;
          break;
        }
      }
      --picnt[i];
      if(flag) res.push_back(i);
    }
    if(res.size()==0) res.push_back(0);
    cout<<res[0];
    REPR(i,res.size())cout<<" "<<res[i];
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC158B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = RLong;
            var A = RLong;
            var B = RLong;

            long div = N / (A + B);
            long rem = N % (A + B);

            long ans = div * A + Math.Min(rem, A);
            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


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

typedef long long ll;
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
const double pi = acos(-1.0);


int n;

// a-b = 1
// a-b-c : a-b =
//
//

// n!/2 => n!/2 * (n-1)
//
// n*(n-1)/2
//
// (n-1)!
//
// n=2 -> 1
// n=3 -> 2
//
// 1-2-3
// 2-1-3
// 1-3-2
//
// 2*()
//   sum*2/n

int x[10],y[10];

int main(){
  cin>>n;
  double sum = 0;
  rep(i,0,n){
    scanf("%d %d",x+i,y+i);
    rep(j,0,i){
      sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  printf("%.15lf\n",sum*2/n);
  return 0;
}


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

int solve() {
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i = 0; i<n; ++i) 
    cin>>h[i];
  int dp[n];
  dp[0] = 0;
  for(int i = 1; i<n; ++i) {
    int j = i-1;
    dp[i] = INT_MAX;
    while(j>=0 and i-j<=k) {
      dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]));
      --j;
    }
  }
  return dp[n-1];
} 

int main() {
  cout<<solve()<<endl;
  return 0;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

vector<vector<long long>> grid;

long long get_sum(const vector<int> &sz) {
  long long sum = 0;
  for (int i = 0; i < sz.size(); ++i) {
    sum += grid[i][sz[i]];
  }
  return sum;
}

int main() { IO;
  vector<int> sz(3);
  for (auto &x : sz) cin >> x;

  int n;
  cin >> n;

  for (int m : sz) {
    vector<long long> v(m + 1);
    for (int i = 1; i <= m; ++i) {
      cin >> v[i];
    }
    sort(v.begin(), v.end());
    grid.push_back(v);
  }

  auto cmp = [](vector<int> a, vector<int> b) { return get_sum(a) < get_sum(b); };
  priority_queue<vector<int>, vector<vector<int>>, decltype(cmp)> pq(cmp);
  set<vector<int>> S;

  pq.push(sz);
  S.insert(sz);

  while (n--) {
    const auto v = pq.top();
    pq.pop();
    cout << get_sum(v) << endl;

    for (int i = 0; i < v.size(); ++i) {
      if (v[i] > 1) {
        vector<int> v2 = v;
        v2[i]--;

        if (S.find(v2) == S.end()) {
          pq.push(v2);
          S.insert(v2);
        }
      }
    }
  }

  return 0;
}


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int n = 0, d = b;
	while (d) {
		n++;
		d /= 10;
	}
	int c = b + a * pow(10, n);
	int e = sqrt(c);
	if (c == e * e) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
  
 int x ,y ,z;
 cin >> x >> y >> z;

 int a, b, c;
 a = y;
 b = x;
 c = a;
 a = z;

 cout << a << ' ' << b << ' ' <<  c << endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

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

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

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    map<int,int> map;
    rep(i,n)map[a[i]]++;
    RSORT(a);
    int ans=0;
    rep(i,n){
        if(!map[a[i]])continue;
        int b=1;
        while(b<=a[i])b<<=1;
        b-=a[i];
        if(!map[b])continue;
        if(a[i]==b&&map[b]==1)continue;
        ans++;
        map[a[i]]--;
        map[b]--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 26880
#include <stdio.h>

int main(void)
{
  int a[100], b[100], score[100]={0}, target, N, M, i, j;

  scanf("%d", &N);
  scanf("%d", &M);

  for(i = 0; i < M; i++)
    scanf("%d", &a[i]);

  for(i = 0; i < M; i++){
    target = a[i];
    for(j = 0; j < N; j++){
      scanf("%d", &b[j]);
      if(target == b[j])
	score[j]++;
      else 
	score[a[i]-1]++;
    }
  }

  for(i = 0; i < N; i++)
    printf("%d\n", score[i]);

  return 0;
}

Measured memory_bytes: 596
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;

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

const int N = (int)2e5 + 9;
const int K = 20;

int dpL[1 << K];
int dpR[1 << K];
int x[N];

int pl[K][N];
int pr[K][N];

int cnt[N];

void update(int cl, int cr){
    cnt[cl] ++ ;
    cnt[cr + 1] -- ;
}

int main(){
    fastIO;
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++ ){
        cin >> x[i];
    }
    vector<int> vl;
    while(k > 0){
        vl.push_back(k);
        k /= 2;
    }
    vl.push_back(0);
    reverse(vl.begin(), vl.end());
    int m = vl.size();
    int z = (1 << m);
    for(int i = 0 ; i < m ; i ++ ){
        pl[i][1] = 1;
        for(int j = 2; j <= n; j ++ ){
            pl[i][j] = pl[i][j-1];
            if(x[j] - x[j - 1] > vl[i]){
                pl[i][j] = j;
            }
        }
        pr[i][n] = n;
        for(int j = n - 1; j >= 1; j -- ){
            pr[i][j] = pr[i][j+1];
            if(x[j + 1] - x[j] > vl[i]){
                pr[i][j] = j;
            }
        }
    }
    for(int i = 0 ; i < z; i ++ )
        dpL[i] = 0, dpR[i] = n + 1;
    int mask;
    for(int i = 0 ; i < z; i ++ ){
        for(int j = 0 ; j < m; j ++ ){
            if(i & (1 << j)) continue;
            mask = i | (1 << j);
            if(dpL[i] == n) dpL[mask] = n;
            else dpL[mask] = max(dpL[mask], pr[j][dpL[i] + 1]);
        }
    }
    for(int i = 0 ; i < z; i ++ ){
        for(int j = 0 ; j < m ; j ++ ){
            if(i & (1 << j)) continue;
            mask = i | (1 << j);
            if(dpR[i] == 1) dpR[mask] = 1;
            else dpR[mask] = min(dpR[mask], pl[j][dpR[i] - 1]);
        }
    }
    int oth;
    int L, R;
    for(int i = 0 ; i < (1 << (m - 1)); i ++ ){
        oth = (1 << (m - 1)) - i - 1; 
        L = dpL[i];
        R = dpR[oth];
        if(R-L <= 2){
            update(1, n);
        }
        else{
            if(pr[m - 1][L + 1] >= R-1){
                update(pl[m - 1][L + 1], pr[m - 1][L + 1]);
            }
        }
    }
    for(int i = 1; i <= n; i ++ ){
        cnt[i] += cnt[i - 1];
        if(cnt[i] > 0)
            cout << "Possible\n";
        else
            cout << "Impossible\n";
    }
    return 0;
}

Measured memory_bytes: 43392
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int total = 0;
        sc.close();

        for(int i = 1; i <= n; i++) {

            int sum = digitSum(i);
            if (sum >= a && sum <=b){
                total += i;
            }
        }
        System.out.println(total);

    }

    private static int digitSum(int i) {
        int sum = 0;
        do {
            sum += i % 10;
            i = i / 10;
        } while (i > 0);
        return sum;
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
string s;
int main(){
    cin>>s;
    string s1(s);
    reverse(s.begin(),s.end());
    rep(i,0,(int)s.size()-1){
        if(s1[i]=='b')s1[i]='d';
        else if(s1[i]=='d')s1[i]='b';
        else if(s1[i]=='p')s1[i]='q';
        else if(s1[i]=='q')s1[i]='p';
    }
    if(s1==s)printf("Yes");
    else printf("No");
    return 0;
}

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

int main() {
    vector<string> s(3);
    cin >> s[0] >> s[1] >> s[2];
    
    int idx = 0;
    while (true) {
        if (s[idx].empty()) break;
        
        char c = s[idx][0];
        s[idx].erase(s[idx].begin());
        idx = c - 'a';
    }
    
    cout << char('A' + idx) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
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);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	int x, a, b;
	cin >> x >> a >> b;
	int p = abs(x - a), q = abs(x - b);
	if (p < q)puts("A");
	else puts("B");
	ggr
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define clr clear()
#define ins insert
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define mem(x,val) memset((x),(val),sizeof(x));
#define cusmem(x,val) for(auto &i:x) i=val;
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);\
            cin.tie(NULL);\
            cout.tie(NULL);
using namespace std;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int>pli;
typedef vector<ll> vl;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
string impossible;

mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
// const int N=6;
const int N=4e5+5;
const int L=41;
int MOD=1e9+7;
ll n,m,k,i,j;
bool f0,f1,f2;
const int MAXN=2e3;
int main(){
    #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin); 
            freopen("output.txt","w",stdout);
    #endif
    fastio
    cout<<fixed<<setprecision(11);
    int tests=1;    
    // cin>>tests;
    for(int te=1;te<=tests;te++){
        ll n;   cin>>n;
        ll a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ll nxt=0,sum=0;
        for(int i=0;i<n;i++){
            sum+=max(nxt-a[i],0LL);
            nxt=max(nxt,a[i]);
        }
        cout<<sum<<"\n";

    }
    return 0;
}





Measured memory_bytes: 5216
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
use proconio::marker::Chars;
//use proconio::marker::Usize1;
//use std::collections::HashSet;
//use std::collections::HashMap;
//use std::collections::BTreeMap;
//use std::cmp::*;
//use std::num;

fn main() {
    input! {
       s:Chars,t:Chars
    }
    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4000
#include <stdio.h>
 
int main() {
	int i, j, n, m;
	int k[30], a[31][30];
	int jsoe;
	int count = 0;
 
	scanf("%d %d", &n, &m);
 
	for (i = 0; i < 31; i++) {
		for (j = 0; j < 30; j++) {
			a[i][j] = 0;
		}
	}
 
	for (i = 0; i < n; i++) {
		scanf("%d", &k[i]);
		for (j = 0; j < k[i]; j++) {
			scanf("%d", &jsoe);
			a[i][jsoe - 1] = 1;
		}
	}
 
	for (j = 0; j < 30; j++) {
		for (i = 0; i < 30; i++) {
			a[30][j] += a[i][j];
		}
		if (a[30][j] == n) count++;
	}
	
	printf("%d\n", count);
 
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int a, v; cin >> a >> v;
  int b, w; cin >> b >> w;
  int t; cin >> t;

  int d = abs(a - b);
  if(v < w){
    cout << "NO" << endl;
    return 0;
  }

  if(d - (v - w) * t <= 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    return 0;
}

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


int main() {
    int N;
    cin >>N;
    if(N>999)cout<<"ABD"<<endl;
    else cout <<"ABC"<<endl;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<std::vector<char> > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int n, m, x; 
    cin >> n >> m >> x;
    
    v_ll c(n); 
    v2_ll a(n, v_ll(m, 0));

    irep(i, n) {
        cin >> c[i];
        irep(j, m) {
            int tmp;
            cin >> tmp;
            a[i][j] = tmp;
        }
    }
    ll ans = INF;
    for(int i = 0; i < (1<<n); i++) {
        v_ll s(m, 0);
        ll cost = 0;
        for(int j = 0; j < n; j++) {
            if(i & (1<<j)) {
                cost += c[j];
                for(int k = 0; k < m; k++) {
                    s[k] += a[j][k];
                }
            }
        }
        bool t = true;
        irep(k, m) {
            if(s[k] < x) {
                t = false;
            }
        }
        if(t) {
            ans = min(ans, cost);
        }
    }
    if(ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans  <<endl;
    }
    return 0;
}
/** atcoder **/


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;

#define all(s) s.begin(),s.end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

void rw()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

int main()
{
	speed;
	//rw();

	ll n, x;
	cin >> n;

	vector<ll> r;
	for (int i = 0; i < n; i++)
		cin >> x, r.push_back(x);

	sort(all(r));
	x = 0;
	if (r.size() > 2)
	{
		n = r.size();
		for (int i = 0; i < n; i++)
		{
			for (int j = i + 1; j < n; j++)
			{
				for (int k = j + 1; k < n; k++)
					if (r[i] + r[j] > r[k] && r[i] != r[j] && r[j] != r[k] && r[k] != r[i])
						x++;
			}
		}
	}
	else
		x = 0;

	cout << x;
	return 0;
}


Measured memory_bytes: 3660
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int n;
vector<string> city;
string tmp[15];
int dp[1<<15][15];
int cost[15][15];
bool ng[15];
const int inf=512;

int main(){
	
	while(cin>>n,n){

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

		fill(&ng[0],&ng[n],false);
		//?????¨?????????????????????????????????
		for(int i=0;i<n;i++){
			if(ng[i]) continue;
			for(int j=0;j<n;j++){
				if(i==j) continue;

				if(tmp[i].find(tmp[j])!=string::npos) ng[j]=true;
			}
		}
		city.clear();
		for(int i=0;i<n;i++){
			if(!ng[i]) city.push_back(tmp[i]);
		}

		n=city.size();
		const int N=1<<n;
		
		fill(&dp[0][0],&dp[N][n],inf);
		fill(&cost[0][0],&cost[n][n],inf);

		for(int i=0;i<n;i++){
			dp[1<<i][i]=city[i].size();
		}

		//city[i]????????????city[j]?????????????????????
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j) cost[i][j]=0;
				//city[i]???????????????len????????¨city[j]????????????len??????????????????
				int li=city[i].size(),lj=city[j].size();
				for(int len=min(li,lj);len>=0;len--){
					if(city[i].substr(li-len,len)==city[j].substr(0,len)){
						cost[i][j]=lj-len;
						break;
					}
				}
			}
		}

		for(int bit=1;bit<N;bit++){
			for(int from=0;from<n;from++){
				if(!(bit&(1<<from))) continue;
				for(int to=0;to<n;to++){
					if(bit&(1<<to)) continue;
					dp[bit|(1<<to)][to]=min(dp[bit|(1<<to)][to],dp[bit][from]+cost[from][to]);
				}
			}
		}
		
		cout<<*min_element(dp[N-1],dp[N])<<endl;

	}

}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, T; cin>>N>>T;
    vector<P> nt;
    rep(i, N){
        int c,t; cin>>c>>t;
        nt.emplace_back(c,t);
    }
    sort(nt.begin(), nt.end());
    rep(i, N){
        if(nt[i].second<=T) {
            cout << nt[i].first<<endl;
            return 0;
        }
    }
    cout <<"TLE" <<endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		Map<Integer, Integer> A = new HashMap<Integer, Integer>();

		int tmp = 0;
		for (int i = 0; i < Q; i++) {
			tmp = sc.nextInt();
			if (A.get(tmp) != null) {
				A.put(tmp, A.get(tmp) + 1);
			} else {
				A.put(tmp, 1);
			}
		}

		for (int i = 1; i < N+1; i++) {
			if (A.get(i) == null) {
				A.put(i, 0);
			}
			if (K - Q + A.get(i) > 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}

	}
}


Measured memory_bytes: 89116
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 2000

int n;
ll z,w;
ll a[MAX_N];
ll dp[MAX_N + 1][2][2][MAX_N + 1];

ll rec(int depth, bool now, bool ok, int have){
    if(dp[depth][now][ok][have] != -1) return dp[depth][now][ok][have];
    if(depth == n){
        ll X, Y;
        if(now){
            X = a[depth - 1];
            Y = a[have];
        }else{
            Y = a[depth - 1];
            X = a[have];
        }
        if(have == n) Y = w;
        return dp[depth][now][ok][have] = abs(X - Y);
    }
    ll res;
    if(now){
        res = 0;
        res = max(res, rec(depth + 1, true, true, have));
        if(ok) res = max(res, rec(depth + 1, false, false, depth));
    }else{
        res = INF;
        res = min(res, rec(depth + 1, false, true, have));
        if(ok) res = min(res, rec(depth + 1, true, false, depth));
    }
    return dp[depth][now][ok][have] = res;
}

signed main(){
    cin >> n >> z >> w;
    REP(i,n){
        cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << rec(0, true, false, n) << endl;
    return 0;
}

Measured memory_bytes: 125568
/*
    Author: Mohammad faisal
    Problem: One Clue.
    Date: 10/08/2019

*/
// #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<numeric>
using namespace std;
// #define unsigned long long int ull
// long long gcd(long long a,long long b)
// {
//   if(b)
//     return gcd(b,a%b);
//   else
//     return a;
// }
// Author: Mohammad Faisal
// // #include<iostream>
// // #include<map>
// using namespace std;
int main()
{

    int k,x;
    cin >>  k >> x;
    if(k==1){
      cout<<x;
      return 0;
    }
    vector<int> v;
    int count=0;
    for(int i=1; ;i++){
      v.push_back(i+x);
      v.push_back(x-i);
      count++; 
      if(count==k-1)
        break;
    }
    v.push_back(x);
    sort(v.begin(),v.end());
    for(vector<int>::iterator it=v.begin();it!=v.end();it++)
    {
      cout<<*it<<" ";
    }
    v.clear();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 const int MOD = 1e9 + 7, N = 2005; 
int C[N][N]; int main() 
{  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 
 C[0][0] = 1;
  for(int i = 1; i < N; i++)
 {    C[i][0] = 1;   
 for(int j = 1; j < N; j++) 
{      C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; 
     if(C[i][j] >= MOD) C[i][j] -= MOD;    } 
 } 
 int n, k; 
cin >> n >> k; 
 for(int i = 1; i <= k; i++)
 {    cout << (1ll * C[n - k + 1][i] * C[k - 1][i - 1] % MOD) << "\n"; 
}
}

Measured memory_bytes: 16000
n=int(input())
l=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    l[u].append((v,w))
    l[v].append((u,w))


iro=[-1]*n
iro[0]=1
from collections import deque
q=deque()
q.append(0)
while q:
    v=q.popleft()
    for i,w in l[v]:
        if iro[i]!=-1:
            continue
        if w%2==0:
            iro[i]=iro[v]
        else:
            iro[i]=iro[v]^1
        q.append(i)
print(*iro,sep="\n")


Measured memory_bytes: 70688