akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int n,m;
    while (cin >> n >> m) {
        if(n == 0 && m == 0)return 0;
        vector<int> A,B;
        for(int a = 0;a < n;a++){
            int b;cin >> b;
            A.push_back(b);
        }
        for(int a = 0;a < m;a++){
            int b;cin >> b;
            B.push_back(b);
        }
        int X = accumulate(A.begin(),A.end(),0);
        int Y = accumulate(B.begin(),B.end(),0);
        vector<pair<int,pair<int,int>>> anses;
        for(int  a = 0;a < n;a++){
            for(int b = 0;b < m;b++){
                if(X-A.at(a)+B.at(b) == Y-B.at(b)+A.at(a)){
                    anses.push_back(make_pair(A.at(a)+B.at(b),make_pair(A.at(a),B.at(b))));
                }
            }
        }
        sort(anses.begin(),anses.end());
        if(anses.empty()){
            cout<<-1<<endl;
        }else{
            cout<<anses.front().second.first<<" "<<anses.front().second.second<<endl;
        }
    }
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long H;
    int N;
    vector<int>A(100010);
    cin>>H>>N;
    for(int i=0;i<N;++i)cin>>A[i];

    long long sum=0;
    for(int i=0;i<N;++i){
        sum+=A[i];
    }
  
    if(H<=sum)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 640
n = int(input())
a = input()
b = input()
c = input()

ans = 0
for aa, bb, cc in zip(a,b,c):
  if aa == bb and bb == cc:
    pass
  elif aa == bb or bb == cc or cc == aa :
    ans += 1
  else :
    ans += 2
print(ans)



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

int main() {
  int n, a, b, x;
  cin >> n >> a >> b;
  
  x = n * a ;
  
  if(x <=  b){
    cout << x << endl;
  }
  else{
    cout << b << endl;
  }
}

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

int main() {
	int s[4];
	int Pair[4] = { -1,-1,-1,-1 };

	bool flg = true;

	for (int i = 0; i < 4; ++i) {
		
		cin >> s[i];
		
		for (int i2 = 0; i2 < i; ++i2) {
			
			if (Pair[i] != -1) {
				continue;
			}
			if (s[i] == s[i2]) {
				
				Pair[i] = i2;
				Pair[i2] = i;
				break;
			}
		}
	}

	for (int i = 0; i < 4; ++i) {
		
		if (Pair[i] == -1) {
			
			flg = false;
			break;
		}
	}

	cout << ( flg ? "yes" : "no" ) << endl;

	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  int N, M, ans = 0, okashi = 0, score = 0, A, B ;
  cin >> N >> M ;
  int ten[N+1], goodten[N+1] ;
  for(int i=1;i<(N+1);i++){
    cin >> ten[i] ;
    goodten[i] = 1 ;
  }
  for(int i=0;i<M;i++){
    cin >> A >> B ;
    if(ten[A] >= ten[B]) goodten[B] = 0 ;
    if(ten[A] <= ten[B]) goodten[A] = 0 ;
  }
  for(int i=1;i<(N+1);i++){
    ans += goodten[i] ;
  }
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;


int main()
{
	int k; cin >> k;
	string s; cin >> s;
	if(s.size() <= k) cout << s << endl;
	else cout << s.substr(0, k) + "..." << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  int maxn=a[0], pmaxn = a[0];
  rep(i, n) {
    cin >> a[i];
    if(a[i] > maxn) {
      pmaxn = max(pmaxn, maxn);
      maxn = a[i];
    } else {
      pmaxn = max(pmaxn, a[i]);
    }
  }

  rep(i, n) {
    if(a[i] == maxn) cout << pmaxn << endl;
    else cout << maxn << endl;
  }
  return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
int getrand(int l, int r) { // [l, r]
    static random_device rd;
    static uint32_t y = time(NULL);
    y = y ^ (y << 13); y = y ^ (y >> 17);
    y = y ^ (y << 5);
    return y % (r - l + 1) + l;
}
vector<int> makePermutation(int n, int loop = 101010) {
    vector<int> v(n);
    rep(i, 0, n) v[i] = i + 1;
    rep(j, 0, loop) {
        int a = getrand(0, n - 1);
        int b = getrand(0, n - 1);
        swap(v[a], v[b]);
    }
    return v;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/

int N, A[101010];
//---------------------------------------------------------------------------------------------------
int check() {
    rep(i, 0, N) if (A[i] == i) return 0;
    return 1;
}
//---------------------------------------------------------------------------------------------------
int solve() {
    rep(i, 0, N) A[i]--;
    int ans = 0;
    rep(i, 0, N - 1) {
        if (A[i] == i) {
            swap(A[i], A[i + 1]);
            ans++;
        }
    }
    //assert(check());
    if (!check()) ans++;
    return ans;
}
//---------------------------------------------------------------------------------------------------
vector<int> v;
void _main() {

    cin >> N;
    rep(i, 0, N) cin >> A[i];
    cout << solve() << endl;
    return;

    rep(i, 0, 1001) {
        N = 10;
        v = makePermutation(10);
        rep(j, 0, 10) A[j] = v[j];
        solve();
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;


signed main(){
  int n,p;
  while(cin>>n>>p,n!=0){
    int sum=p;
    vector<int> x(n);
    for(int i=0;;){
      if(p){
        x[i%n]++;
        p--;
      }else{
        p+=x[i%n];
        x[i%n]=0;
      }
      if(x[i%n]==sum){
        cout<<i%n<<endl;
        break;
      }
      i++;
    }
  }
  return 0;
}



Measured memory_bytes: 2972
S = input()
S = S[::-1]
W = ['dream', 'dreamer', 'erase', 'eraser']
for n in range(4):
    W[n] = W[n][::-1]
check = 0
i = 0
while i < len(S):
    check = 0
    for w in W:
        if w in S[i:i+len(w)]:
            i += len(w)
            check = 1
    if check is 0:
        break
if check is 1:
    print('YES')
else:
    print('NO')


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

int main()
{
  string S;
  cin >> S;
  int l, count = 0;
  l = S.length();
  char A[l], B[l];
  for (int i = 0; i < l; i++)
    B[i] = S.at(i);
  if (B[0] == '0')
  {
    for (int i = 0; i < l; i += 2)
      A[i] = '0';
    for (int i = 1; i < l; i += 2)
      A[i] = '1';
    for (int i = 0; i < l; i++)
    {
      if (A[i] != B[i])
        count++;
    }
    cout << count << endl;
  }
  else
  {
    for (int i = 0; i < l; i += 2)
      A[i] = '1';
    for (int i = 1; i < l; i += 2)
      A[i] = '0';
    for (int i = 0; i < l; i++)
    {
      if (A[i] != B[i])
        count++;
    }
    cout << count << endl;
  }
}
  

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------

int h,w;
string s[50];

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

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> h >> w;

    REP(i, h){
        cin >> s[i];
    }

    REP(i, h){
        REP(j ,w){

            int cnt = 0;

            if (s[i][j] == '#') continue;


            REP(k, 8){

                int ny =  i + dy[k];
                int nx =  j + dx[k];

                if( nx >= 0 && nx < w && ny >= 0 && ny < h
                    && s[ny][nx] == '#'){
                    cnt++;
                }
            }


            s[i][j] = char (cnt + '0');
        }
    }

    REP(i, h){
        cout << s[i] << endl;
    }

    return 0;
}


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

import heapq

n = int(input())
T = [[] for _ in range(n)]
for i in range(1, n):
  a = int(input())
  a -= 1
  T[a].append(i)

def dfs(v):
  if not T[v]:
    return 0
  L = []
  for i in T[v]:
    heapq.heappush(L, dfs(i)+1)
  temp = heapq.heappop(L)
  for _ in range(len(T[v])-1):
    temp = max(temp+1, heapq.heappop(L))
  return temp

ans = dfs(0)
print(ans)

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

using namespace std;

typedef long long ll;

int main(){
	int n, m, x, a;
	cin >> n >> m >> x;
	int up = 0, down = 0;
	for(int i = 0; i < m; i++){
		cin >> a;
		if(a < x)down++;
		else up++;
	}
	cout << min(up, down)  << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key < value;
}

int binary_search(vector<ll> a,ll key){
  ll ok = a.size();
  ll ng = -1;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  string s;cin>>s;
  int a[3]={0};
  for(auto& c : s)a[c-'a']++;
  sort(a,a+3);
  bool ok = a[2]-a[0] <= 1;

  print(ok?"YES":"NO");
  return 0;
}


Measured memory_bytes: 512
#include <stdbool.h>
#include <stdio.h>
int main() {
	int n, a[100000], cnt = 1;
	bool isup;
	bool issame = false;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	if (a[0] < a[1])
		isup = true;
	else if (a[0] > a[1])
		isup = false;
	else
		issame = true;
	for (int i = 1; i < n - 1; i++) {
		if (issame) {
			if (a[i] != a[i + 1]) {
				issame = false;
				if (a[i] < a[i + 1])
					isup = true;
				else
					isup = false;
			}
		} else {
			if (isup && a[i] <= a[i + 1]) {
				;
			} else if (!isup && a[i] >= a[i + 1]) {
				;
			} else {
				if (i + 2 < n) {
					if (a[i + 1] < a[i + 2])
						isup = true;
					else if (a[i + 1] > a[i + 2])
						isup = false;
					else
						issame = true;
					cnt++;
				} else {
					cnt++;
					break;
				}
			}
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            var a = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();
            List<int> ans = new List<int>();

            for(var i = 0;i < a[1]; i++) {
                Console.ReadLine();
                var y = Console.ReadLine().Trim().Split(' ').Select(_=>int.Parse(_));
                foreach(var z in y) {
                    if (!ans.Contains(z)) {
                        ans.Add(z);
                    }
                }
            }
            int b = a[0] - ans.Count();
            Console.Write(b);
        }
    }
}

Measured memory_bytes: 28412
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  int n;
  cin >> n;

  vector<int> a(n);
  FOR(i, 1, n) {
    cin >> a[i];
    a[i]--;
  }

  vec b(n, 0);

  FOR(i, 1, n){
    b[a[i]] ++;
  }

  REP(i, n){
    cout << b[i] << endl;
  }
  
 
  return 0;
}


Measured memory_bytes: 6348
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

namespace detail {
template <typename Tp, size_t N>
std::vector<Tp> make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N == 1), const Tp&>::type x
) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N > 1), const Tp&>::type x
) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
      size, make_vector<Tp, N-1>(sizes, x)
  );
}
}  // detail::

template <typename Tp, size_t N>
auto make_vector(const size_t(&sizes)[N], const Tp& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

int main() {
  auto dp = make_vector<int>({1000_zu, 11_zu, 21_zu}, 0);
  {
    size_t y = 999;
    size_t m = 10;
    size_t d = 20;
    dp[y][m][d] = 1;
    while (y >= 1 && m >= 1 && d >= 1) {
      size_t y1 = y;
      size_t m1 = m;
      size_t d1 = d-1;
      if (d1 == 0) {
        --m1;
        d1 = 20;
        if (m1 == 0) {
          --y1;
          m1 = 10;
        }
        if (y1 % 3 > 0 && m1 % 2 == 0) d1 = 19;
      }
      dp[y1][m1][d1] = dp[y][m][d] + 1;
      y = y1;
      m = m1;
      d = d1;
    }
  }

  size_t n;
  scanf("%zu", &n);
  for (size_t i = 0; i < n; ++i) {
    size_t y, m, d;
    scanf("%zu %zu %zu", &y, &m, &d);
    printf("%d\n", dp[y][m][d]);
  }
}



Measured memory_bytes: 3992
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val st = (0 until n).map { sc.next() to sc.next().toInt()  }
    val x = sc.next()
    println(problem006a(n, st, x))
}

fun problem006a(n: Int, st: List<Pair<String, Int>>, x: String): Int {
    var sum = 0
    var start = false
    for (i in 0 until n) {
        if (start) {
            sum += st[i].second
        }
        if (st[i].first == x) start = true
    }
    return sum
}

Measured memory_bytes: 31512
N, M = map(int, input().split())
cnt = 0
A = list(map(int, input().split()))
s = sum(A)
for i in range(N):
  if(A[i] >= (s/(4 * M))):
    cnt += 1
if(cnt >= M):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
NDIGIT=50
N,K=map(int,input().split())
A=list(map(int,input().split()))
acc=[0]*(N+1)
tmp=0
for i in range(N):
    tmp+=A[i]
    acc[i+1]=tmp

nums=[]
for i in range(N):
    for j in range(i+1,N+1):
        n=acc[j]-acc[i]
        s=bin(n)[2:]
        s="0"*(NDIGIT-len(s))+s
        nums.append(s)
        
ans=[]
for i in range(NDIGIT):
    tmp = [s for s in nums if s[i]=="1"]
    if len(tmp)>=K:
        ans.append("1")
        nums=tmp
    else:
        ans.append("0")

print(int("".join(ans),2))


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

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];
    
    ll ans = 0;
    rep(i, 1, N){
        if(A[i-1] < A[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){
      ans *=(n+1-j);
      ans /= j;
      ans %= MOD;} }return ans;}


void solve()
{
  int n; cin >> n;
  bool visited[n+1];
  int go[n + 1];
  go[0] = 0;
  visited[0] = false;
  for(int i = 1; i <= n; ++i) {
    cin >> go[i];
    visited[i] = false;
  }
  int ans = 1;
  int now = go[1];
  visited[1] = true;
  visited[now] = true;
  while(now != 1){
    if(now == 2) {
      cout << ans << endl;
      return;
    }
    if(visited[go[now]]) break;
    visited[now] = true;
    now = go[now];
    ans++;
  }
  cout << -1 << endl;
}

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


Measured memory_bytes: 4112
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
ll fact(ll n)
{
ll    res=1;
    for(int i = 1; i <= n;i++){
    res = res * i ;
}
return res;
}
ll pw(ll a, ll n)
{
    ll ans=1;
    while(n>0)
    {
        if (n%2!=0)
        {
            ans=ans*a;
        }
        a=a*a;
        n=n/2;
    }
    return ans;
}



int main()
{   IOS;
cout.precision(30);

   ll a;
   cin >> a; vector<ll> L;
   for(int i=0;i<a;i++)
   {
       ll x;
       cin >> x;
       L.push_back(x);
   }
    vector<ll> L2;
    L2=L;
    ll res=0;
    sort(L2.begin(),L2.end());
    for(int i=0;i<a;i++)
        if(L[i]!=L2[i])
            res++;
    if (res==2 || res==0) cout << "YES";
    else cout<< "NO";
    return 0;
}


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

int main()
{

    ll N, A, B;
    cin >> N >> A >> B;

    if (A == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    ll tmp, a, b;

    tmp = floor(N / (A + B));
    a = N % (A + B);
    b = (A > a) ? a : A;
    cout << tmp * A + b << endl;
    return 0;
}


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

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

// rep
//------------------------------------------
#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()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int a, b;
signed main()
{
    int sum = 0;
    cin >> a >> b;
    if (a < b) {
        sum += b;
        b--;
    } else {
        sum += a;
        a--;
    }

    cout << sum + max(a, b) << endl;
    return 0;
}

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

int main() {
	
	int n,sum1=0,sum2=0;
	cin>>n;
	int a[2][n];
	for(int i=0;i<2;i++)
	{
	    
	    for(int j=0;j<n;j++)
	    {
	    cin>>a[i][j];
	   // cout<<ar[i][j];
	    }
	    
	    //cout<<" \n";
	    
	}
	int k;
	for(k=0;k<n;k++)
	{
	    sum1=0;
	   
	    for(int l=0;l<=k;l++)
	    {
	        sum1=sum1+a[0][l];
	        
	    }
	    //cout<<sum1<<" \n";
	    for(int m=k;m<n;m++)
	    sum1=sum1+a[1][m];
	    
	     if(sum2<sum1)
	     sum2=sum1;
	   
	   
//	 cout<<sum2<<"\n"; 
	    
	}
	
	
	cout<<sum2;
	
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll  MAX=510000;
const ll MOD=1000000007;
ll fanc[MAX],inv[MAX],finv[MAX];

//n^p(mod M)を繰り返し2乗法で求める
ll Repeat(ll n,ll p,ll m){
  if(p==0)return 1;
  if(p%2==0){
    ll t=Repeat(n,p/2,m);
    return t*t%m;
  }
  return n*(Repeat(n,p-1,m));
}
//前処理
void COMinit(){
  fanc[0]=fanc[1]=1;
  inv[1]=1;
  finv[0]=finv[1]=1;
  for(int i=2;i<MAX;i++){
    fanc[i]=fanc[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
//二項係数
ll COM(ll n,ll k){
  if(n<0||k<0)return 0;
  if(n<k)return 0;
  return fanc[n-k+1]*(finv[n-k]%MOD)%MOD;
}
int main(){
  COMinit();
  ll n,a,b;
  cin>>n>>a>>b;
  ll all=Repeat(2,n,MOD);
  ll v1 = 1;
  for (ll i = n; i > n - a; i--) {
        v1 *= i;
        v1 %= MOD;
  }
  ll v2 = 1;
  for (ll i = n; i > n - b; i--) {
      v2 *= i;
      v2 %= MOD;
    }  
  v1=v1*(finv[a]%MOD)%MOD;
  //cout<<v1<<endl;
  v2=v2*finv[b]%MOD;

  ll ans=all-1-v1-v2;
  while(ans<0){
    ans += MOD;
  }
    
    ans %= MOD;
  cout<<ans<<endl;
}

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

int main() {
    string s;
    int count = 0;
    
    cin >> s;
    
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '2'){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll K;
ll data[100002];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> K;
    for(int i = 0; i < N; ++i){
        int a, b;
        cin >> a >> b;
        data[a] += b;
    }
    ll sum = 0;
    int num = 0;
    while(sum < K){
        ++num;
        sum += data[num];
    }
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n);
	int cnt=0;
	rep(i,n){
		cin>>a[i];
		int x=a[i];
		while(x%2==0){
			cnt++;
			x/=2;
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;
const int inf = 1e9;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m),c(m);
    rep(i,m){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--,b[i]--;
    }

    vector<vector<int> >dist(n,vector<int>(n,inf));
    rep(i,n)dist[i][i]=0;
    rep(i,m){
        dist[a[i]][b[i]]=c[i];
        dist[b[i]][a[i]]=c[i]; 
    }

    rep(k,n)rep(i,n)rep(j,n){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    }

    int ans = m;
    rep(i,m){
        bool is_shortest = false;
        rep(j,n){
            if(c[i]+dist[b[i]][j]==dist[a[i]][j])is_shortest=true;
        }
        if(is_shortest)ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
data class Plan(val t: Int, val x: Int, val y: Int)

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val plans = Array(n + 1, {
        if (it == 0) {
            Plan(0, 0, 0)
        } else {
            val (t, x, y) = readLine()!!.split(" ").map(String::toInt)
            Plan(t, x, y)
        }
    })
    for (k in 0 until n) {
        val dt = plans[k + 1].t - plans[k].t
        val distance = Math.abs(plans[k + 1].x - plans[k].x) + Math.abs(plans[k + 1].y - plans[k].y)
        if (distance > dt || distance % 2 != dt % 2) {
            println("No")
            return
        }
    }
    println("Yes")
}


Measured memory_bytes: 64012
#include <stdio.h>
#include <stdlib.h>

int main(void) {
   char c = 0;
   int count[26] = {};

   while(scanf("%c", &c) != EOF) {
       if('A' <= c && c <= 'Z') {
           count[c - 'A']++;
       }
       else if('a' <= c && c <= 'z') {
           count[c - 'a']++;
       }
   }
   int i;
   for(i = 0; i < 26; i++) {
       printf("%c : %d\n", ('a' + i), count[i]);
   }

   return 0;

}

Measured memory_bytes: 540
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  string p,q,r;
  cin >> p>>q>>r;
  
  char ban = 'a';
  
  while(1){
    if(ban=='a'){
      if(p[0]=='a'){
      ban = 'a';
      p.erase(0,1);
      }
      else if(p[0]=='b'){
      ban = 'b';
      p.erase(0,1);
      }
      else if(p[0]=='c'){
      ban = 'c';
      p.erase(0,1);
      } 
    }
    else if(ban=='b'){
      if(q[0]=='a'){
      ban = 'a';
      q.erase(0,1);
      }
      else if(q[0]=='b'){
      ban = 'b';
      q.erase(0,1);
      }
      else if(q[0]=='c'){
      ban = 'c';
      q.erase(0,1);
      } 
    }
    else if(ban=='c'){
      if(r[0]=='a'){
      ban = 'a';
      r.erase(0,1);
      }
      else if(r[0]=='b'){
      ban = 'b';
      r.erase(0,1);
      }
      else if(r[0]=='c'){
      ban = 'c';
      r.erase(0,1);
      } 
    }
    if(p=="" && ban=='a') {
      puts("A");
      return 0;
    }
    if(q=="" && ban=='b') {
      puts("B");
      return 0;
    }
    if(r=="" && ban=='c') {
      puts("C");
      return 0;
    }
  }  
}


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

using namespace std;
const int MAX = 1000000; 
int main(void){
    
    bool prime[MAX];
    fill(prime, prime + MAX, true);
    prime[1] = false;
    for (int i = 4; i < MAX; i += 2) prime[i] = false;
    for (int i = 3; i < MAX; i += 2) {
        if (prime[i]) {
            for (int j = 2; i * j < MAX; ++j) {
                prime[i*j] = false;
            }
        }
    }
    int a, d, n;
    while (cin >> a >> d >> n && a && d && n) {
        int i = 0, res = 0;
        while (n > 0) {
            int num = a + i * d;
            if (prime[num]) {
                --n;
                res = num;
            }
            ++i;
        }
        cout << res << endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 4032
#include <iostream>
#include <cmath>

int main()
{
    double x = 0.0, y = 0.0;
    const double pi = acos(-1.0);

    int prev_deg = 90;
    while (true) {
        int dist, deg;
        char comma;
        std::cin >> dist >> comma >> deg;
        if (dist == 0 && deg == 0) break;

        x += dist * cos(prev_deg * pi / 180);
        y += dist * sin(prev_deg * pi / 180);

        prev_deg -= deg;
    }

    std::cout << (int)x << "\n" << (int)y << std::endl;
}

Measured memory_bytes: 1168
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class APair {
public:
	void solve(istream& in, ostream& out) {
	    int k; in >> k;
	    int a = k / 2;
	    int b = k - a;
	    out << a * b << endl;
	}
};

int main() {
	APair solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n, k;
string s;



int main()
{
	cin >> a >> k;
	n = 1;int t = 0;
	for (int i = 0; n < k&&i<a; i++)
	{
		n *= 2; t++;
	}
	n = n + k *(a - t);

	printf("%d\n",n);
	return 0;
}


Measured memory_bytes: 256
//ABC 176 D--Wizard in Maze 
//题目地址：https://atcoder.jp/contests/abc176/tasks/abc176_d
//题解地址：https://atcoder.jp/contests/abc176/editorial/79
 
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll h,w,cx,cy,dx,dy;
    cin >> h >> w >> cx >> cy >> dx >> dy;
    cx--;
    cy--;
    dx--;
    dy--;
    string s[h];
    for (ll i=0;i<h;i++)cin >> s[i];
    deque<P> que;

    que.push_back(P(cx,cy));
    bool visited[h][w];
    ll d[h][w];
    for (ll i=0;i<h;i++){
        fill(visited[i],visited[i]+w,false);
        fill(d[i],d[i]+w,INF);
    }
    d[cx][cy]=0;
    visited[cx][cy]=true;

    while(!que.empty()){
        P p=que.front();
        ll X=p.first,Y=p.second;
        if (X==dx and Y==dy){
            cout << d[X][Y] << endl;
            return 0;
        }
        visited[X][Y]=true;
        que.pop_front();
        for (ll i=-2;i<3;i++){
            for (ll j=-2;j<3;j++){
                ll x=X+i,y=Y+j;
                if (x<h and x>=0 and y<w and y>=0 and s[x][y]=='.'){
                    if (visited[x][y])continue;
                    if (abs(i)+abs(j)<2){
                        que.push_front(P(x,y));
                        d[x][y]=d[X][Y];
                        visited[i][j]=true;
                    }else{
                        if (d[X][Y]+1<d[x][y]){
                            d[x][y]=d[X][Y]+1;
                            que.push_back(P(x,y));
                        }
                    }
                }
            }
        }

    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 14320
#include <bits/stdc++.h>
#define rep(i,n,k) for(int i=k;i<n;++i)
using namespace std;

int main(){
  long long int n, a, min, ans;
  cin >> n;
  min = n;
  rep(i, 5, 0){
    cin >> a;
    if(min > a) min = a;
  }
  if(n % min == 0) ans = n / min + 4;
  else ans = n / min + 5;
  cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
N, M = map(int, input().split())
K, S = [], []
for i in range(M):
    tmp = list(map(int, input().split()))
    K.append(tmp[0])
    S.append(tmp[1:])
P = list(map(int, input().split()))

ans = 0
for bit in range(2**N):
    lamp = 0
    switch = [0] * N
    # インデックスに対応したランプがついてる(1, 0)ように変換
    for j in range(N):
        if (bit >> j) & 1 == 1:
            switch[j] = 1
    # 各電球ごとに確認
    for i in range(M):
        cnt = 0
        for k in range(N):
            if k+1 in S[i] and switch[k] == 1:
                cnt += 1
        # print("cnt", cnt)
        if cnt % 2 == P[i]:
            lamp += 1
    if lamp == M:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import numpy as np
import sys
buf = sys.stdin.buffer

H,W = map(int,buf.readline().split())
# 周りに壁を、0,1化、壁を0で持つ
grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'.').reshape((H,W+1))

# x軸方向の集計
def F(transpose):
  x = grid
  if transpose:
    x = (x.T).copy()
  x = np.ravel(x) # to 1D array
  L = len(x)
  
  left_zero = np.where(x,0,-np.arange(L)) # 左の壁のindexの-1倍
  np.minimum.accumulate(left_zero, out=left_zero)
  
  right_zero = np.where(x[::-1],0,np.arange(L)) # 逆順ソートした上で左の壁のindex
  np.maximum.accumulate(right_zero, out=right_zero)
  
  y = left_zero
  y += L-right_zero[::-1]
  
  return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
  
answer = (F(False) + F(True)).max()-5
print(answer)


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

 
/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
 
 
ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/

int main(){
    string S;
    cin>>S;
    int Q;
    cin>>Q;
    int rv=0;
    for(int i=0;i<Q;i++){
        int t;
        cin>>t;
        if(t==1){
            rv++;
        }
        if(t==2){
            int f;
            cin>>f;
            char c;
            cin>>c;
            if((f+rv)%2==0){
                S.push_back(c);
            }
            else{
                S.insert(S.begin(),c);
            }
        }
    }
    if(rv%2==1){
        reverse(S.begin(),S.end());
    }
    cout<<S<<endl;
}

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

using namespace std;

const int N = 300 + 5;

int n, m, l;
long long dp[N][N];

int main ()
{
	scanf ("%d%d%d", &n, &m, &l);
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
			dp[i][j] = INT_MAX;
	for (int i = 1; i <= n; ++i)
		dp[i][i] = 0;
	for (int i = 1; i <= m; ++i)
	{
		int x, y, z;
		scanf ("%d%d%d", &x, &y, &z);
		if (z <= l) dp[x][y] = dp[y][x] = min (dp[x][y], 1LL * z);
	}
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (dp[i][k] + dp[k][j] <= l)
					dp[i][j] = min (dp[i][j], dp[i][k] + dp[k][j]);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dp[i][j] == dp[0][0])
				dp[i][j] = -1;
			else if (dp[i][j] > 0)
				dp[i][j] = 1;
			else  dp[i][j] = 0;
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (dp[i][k] != -1 && dp[k][j] != -1)
				{
					if (dp[i][j] == -1)
						dp[i][j] = dp[i][k] + dp[k][j];
					else dp[i][j] = min (dp[i][j], dp[i][k] + dp[k][j]);
				}
	int q;
	scanf ("%d", &q);
	while (q--)
	{
		int x, y;
		scanf ("%d%d", &x, &y);
		printf ("%lld\n", dp[x][y] == -1 ? -1 : (dp[x][y] - 1));
	}
	return 0;
}




































Measured memory_bytes: 1280
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    ll N;
    cin >> N;
    int ans = 20;
    for (ll n = 1; n <= (ll)sqrt(N); n++) {
        ll a = n;
        if (N % a == 0) {
            if (a != N / a) {
                ll b = N / a;
                int cur_a = 0, cur_b = 0;
                while (a > 0) {
                    a /= 10;
                    cur_a++;
                }
                while (b > 0) {
                    b /= 10;
                    cur_b++;
                }
                ans = min(ans, max(cur_a, cur_b));
            } else {
                int cur_a = 0;
                while (a > 0) {
                    a /= 10;
                    cur_a++;
                }
                ans = min(ans, cur_a);
            }
        }
        // cout << a << "\n";
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<double> a(n);
  double sum = 0;
  for (int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }

  vector<pair<double, int>> b(n);
  for (int i = 0; i < n; i++){
    b[i] = make_pair(abs(a[i] - sum/n), i);
  }

  sort(b.begin(), b.end());
  
  cout << b[0].second << endl;
  
  

  return 0;
}


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

int main()
{
    int n,i,x,m=0;
    cin>>n;
    set<int> s;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(s.count(x))m++;
        s.insert(x);
    }
    cout<<s.size()-m%2;
}


Measured memory_bytes: 4992
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int R_now = scan.nextInt();
		int G_goal = scan.nextInt();

		System.out.println(2 * G_goal - R_now);

	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27064
#include <stdio.h>
#include <stdlib.h> 
int main() {
	int h; int w;
	scanf("%d %d", &h,&w);
	while (h!=0&&w!=0){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				printf("#");
			}
			puts("");
		}
		puts("");
		scanf("%d %d", &h,&w);
	}
	return 0;
}
 


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

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

vector<int> d = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
const ll mod = 1e9 + 7;

int main() {
  while (1) {
    string a, b, c;
    cin >> a;
    
    if (a == "0") break;
    cin >> b >> c;
    
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());

    int sz = (int)a.size();

    ll dp[51][2] = {0};
    dp[0][0] = 1;

    for (int i = 0; i < sz; i++) {
      
      vector<int> dx = d;
      if (i == sz - 1) dx.pop_back();
      if (a[i] != '?') dx = {a[i] - '0'};
      
      for (int x : dx) {
        
        vector<int> dy = d;
        if (i == sz - 1) dy.pop_back();
        if (b[i] != '?') dy = {b[i] - '0'};
        
        for (int y : dy) {
          
          vector<int> dz = d;
          if (i == sz - 1) dz.pop_back();
          if (c[i] != '?') dz = {c[i] - '0'};
          
          for (int z : dz) {
            if ((x + y) % 10 == z) {
              dp[i + 1][(x + y) / 10] += dp[i][0];
              dp[i][0] %= mod;
            }
            if ((x + y + 1) % 10 == z) {
              dp[i + 1][(x + y + 1) / 10] += dp[i][1];
              dp[i][1] %= mod;
            }
          }
        }
      }
    }

    cout << dp[sz][0] % mod << endl;
  }
  return 0;
}



Measured memory_bytes: 3192
from math import ceil
D,G=map(int,input().split())
p=[0]*D
c=[0]*D

for i in range(D):
    p[i],c[i]=map(int,input().split())
_min=101*D

flag=0
while(flag < 2**D):
    
    _G=G
    tmp=0
    max_ind=0
    for i in range(D):
        if(flag & 1<<i):
            _G-=p[i]*(i+1)*100 + c[i]
            tmp+=p[i]
        else:
            max_ind=i
    k=ceil( max([(_G),0]) / (100*(max_ind+1)) )  
    if(k < p[max_ind] or k==0):
        tmp+=k
        _min=min([tmp,_min])
    flag+=1
print(_min) 

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class47
    {
        static void Main()
        {
            var I = Console.ReadLine().Split();
            string ans = "";
            if (I[0][0] > I[1][0])
            {
                for(int i = 0; i < int.Parse(I[0]); i++)
                {
                    ans += I[1].ToString();
                }
                Console.WriteLine(ans);
            }
            else
            {
                for (int i = 0; i < int.Parse(I[1]); i++)
                    ans += I[0].ToString();
                Console.WriteLine(ans);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <math.h>
int
main (void)
{
  double a, b, c, d, e, f;
  while (scanf ("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF)
    {
      double x, y;
      x = (c * e - f * b) / (a * e - b * d);
      if (x == -0)
	x = 0;
      y = -(c * d - f * a) / (a * e - b * d);
      if (y == -0)
	y = 0;
      printf ("%.3f %.3f\n", x, y);
    }
  return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 503, M = N << 2;

int n, m;
char s[N][N], t[N][N];

int main()
{
	n = gi(), m = gi();
	for (int i = 1; i <= n; i+=1) scanf("%s", s[i] + 1);
	for (int i = 1; i <= n; i+=1)
		for (int j = 1; j <= m; j+=1)
			t[i][j] = s[i][j];
	for (int i = 1; i <= n; i+=2)
		for (int j = 2; j < m; j+=1)
			s[i][j] = '#';
	for (int i = 1; i <= n; i+=1) s[i][m] = '#';
	for (int i = 2; i <= n; i+=2)
		for (int j = 2; j < m; j+=1)
			t[i][j] = '#';
	for (int i = 1; i <= n; i+=1) t[i][1] = '#';
	for (int i = 1; i <= n; i+=1) printf("%s\n", s[i] + 1);
	puts("");
	for (int i = 1; i <= n; i+=1) printf("%s\n", t[i] + 1);
	return 0;
}


Measured memory_bytes: 4200
#include <iostream>
#include <string>

using namespace std;
 
int main(void) {
  int n, x, l;
  cin >> n >> x;
  int s = 1;
  int d = 0;
  for (int i = 0; i < n; i++) {
    cin >> l;
    d += l;
    if (d <= x) {
      s++;
    }
  }
  cout << s << endl;
  return 0;
}


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


int main() {
	int n;
	cin >> n;
	int color[9] = {};
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		if (a < 400)color[0]++;
		else if (a < 800)color[1]++;
		else if (a < 1200)color[2]++;
		else if (a < 1600)color[3]++;
		else if (a < 2000)color[4]++;
		else if (a < 2400)color[5]++;
		else if (a < 2800)color[6]++;
		else if (a < 3200)color[7]++;
		else color[8]++;
	}
	int flag = 0;
	for (int i = 0;i < 8;i++) {
		if (color[i] > 0)flag++;
	}
	int maxx = flag + color[8], minn = flag;
	if (color[8] == n)minn = 1;
	cout << minn << " " << maxx << endl;
}

Measured memory_bytes: 256