akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//
        int A, B;
        cin >> A;
        int num = A / 7;
        for (int i = 0; i <= num; i++)
        {
                if ((A - i * 7) % 4 == 0)
                {
                        cout << "Yes" << endl;
                        return 0;
                }
        }
        cout << "No" << endl;
        return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

long long int result[310][310][310] = {};

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

	// result[i][j][k] : 頂点1からの長さiのパスで、
	// パスに含まれるノード数はj個で
	// 頂点1と強連結しているものはk個
	result[0][1][1] = 1;
	for(int i = 0; i < m; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= j; k++){
				result[i + 1][j + 1][k] += result[i][j][k] * (n - j);
				result[i + 1][j + 1][k] = result[i + 1][j + 1][k] % mod;
				result[i + 1][j][k] += result[i][j][k] * (j - k);
				result[i + 1][j][k] = result[i + 1][j][k] % mod;
				result[i + 1][j][j] += result[i][j][k] * k;
				result[i + 1][j][j] = result[i + 1][j][j] % mod;
			}
		}
	}
	cout << result[m][n][n] << endl;
	return 0;
}

Measured memory_bytes: 220800
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!


int _find(int a,int b){
    int outlet=1;
    int ans=0;
    while(outlet<b){
        outlet--;
        outlet+=a;
        ans++;
    }
    return ans;
}
void solve(){
    int a,b;
    cin>>a>>b;
    cout<<_find(a,b)<<endl;
}
 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  char a;
  cin>>a;
  if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o') cout<<"vowel"<<endl;
  else cout<<"consonant"<<endl;
  return 0;
}
	


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void)
{
	char str[21];
	char rev[21];
	int i;
	int j;
	
	scanf("%s", str);
	j = 0;
	
	for(i = strlen(str) - 1; i >= 0; i--){
		rev[j] = str[i];
		j++;
	}
	rev[j] = '\0';
	puts(rev);
	return (0);
	
}

Measured memory_bytes: 524
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int S,h,m,s;
	cin >> S;
	
	h = S / 3600;
	S -= h * 3600;
	
	m = S / 60;
	S -= m * 60;
	
	printf("%d:%d:%d\n", h, m, S);
	return 0;
	
}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int n;
int a[100];

int main(){
	ll int tmp = 1;
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		if(a[i]%2 == 0) tmp*=2;
	}
	ll int ans = 1;
	REP(i, n) ans*=3;
	cout << ans - tmp << endl;
}

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

using namespace std;

long long int a[1000000];
long long int INF = 1000000000000000;

typedef pair<int, int> P;

vector<P> v;

int main(){
	
	int N, L;
	
	cin >> N >> L;
	
	for(int i = 0; i < 1000000; i++){
		a[i] = 0;
	}
	
	for(int i = 0; i < N; i++){
		P p;
		cin >> p.first;
		p.second = i;
		v.push_back(p);
	}
	
	sort(v.begin(), v.end(), greater<P>());
	
	for(int i = 0; i < v.size(); i++){
		int index = v[i].second + 1;
		a[index] = max(a[index - 1], a[index + 1]) + L - v[i].first;
	}
	
	long long int ans = 0;
	
	for(int i = 1; i <= N; i++){
		ans = max(ans, a[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B, R = C + D;
  
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (R == L) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

namespace 競プロ_Csharp {
    class Program {
        static void Main(string[] args) {

            while (true) {

                int[] ar = NextInts();
                if (ar[0] == 0 && ar[1] == 0) return;

                int h = ar[0], w = ar[1];

                for (int i = 0; i < h; i++) {
                    string s = "";
                    for (int j = 0; j < w; j++) {
                        s += "#";
                    }
                    Println(s);
                }

                Println("");

            }

        }

        public static void Println (Object o) {
            Console.WriteLine(o);
        }

        public static string NextString() {
            return Console.ReadLine();
        }

        public static string[] NextStrings () {
            return Console.ReadLine().Split();
        }

        public static int NextInt () {
            return int.Parse(Console.ReadLine());
        }

        public static int[] NextInts () {
            string[] a = Console.ReadLine().Split();
            int[] b = new int[a.Length];
            for (int i = 0; i < a.Length; i++) {
                b[i] = int.Parse(a[i]);
            }
            return b;
        }

        public static double NextDouble () {
            return double.Parse(Console.ReadLine());
        }

    }
}



Measured memory_bytes: 20004
[N,M]=[int(i) for i in input().split()]
H=[int(i) for i in input().split()]
A=[0 for i in range(N)]
ans=0
for i in range(M):
	[x,y]=[int(i) for i in input().split()]
	if H[x-1]-H[y-1]>-1:A[y-1]+=1
	if H[y-1]-H[x-1]>-1:A[x-1]+=1
for i in range(len(A)):
	if A[i]==0:ans+=1
print(ans)

Measured memory_bytes: 85096
from fractions import gcd
from collections import defaultdict

n = int(input())
temp = defaultdict(int)
ans = 0

for i in range(1, n+1):
    for j in range(1, n+1):
      x = gcd(i,j)
      temp[x] += 1

for k,v in temp.items():
  for w in range(1, n+1):
    ans += gcd(k,w)* v

print(ans)

Measured memory_bytes: 10612
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
     int N,x,y;
     cin >> N >> x >> y;
     if(x>y){
         cout << y << endl;
     }else{
         cout << x << endl;
     }
     if(x+y-N>0){
     cout << (x+y)-N << endl;
     }else{
         cout << '0' << endl;
     }
 }

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc157/tasks/abc157_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, M;
  cin >> N >> M;

  VL digits(N, -1);

  rep(i, M) {
    ll s, c;
    cin >> s >> c;
    s--;

    if (s == 0 && c == 0 && N >= 2) drop(-1);
    if (digits[s] != -1 && digits[s] != c) drop(-1);

    digits[s] = c;
  }

  if (N == 1) {
    if (digits[0] == -1) drop(0);
    drop(digits[0]);
  }

  if (digits[0] == -1) digits[0] = 1;

  rep(i, N) {
    if (digits[i] == -1) {
      digits[i] = i == 0 ? 1 : 0;
    }
  }

  rep(i, N) cout << digits[i];

  cout << endl;
}

void solve2() {
  ll N, M;
  cin >> N >> M;

  VPL cons(M);
  rep(i, M) cin >> cons[i].fi >> cons[i].se;

  rep(num, 1000) {
    string str = to_string(num);
    unless(str.size() == N) continue;

    bool ok = true;

    for (auto c : cons) {
      unless(str[c.fi - 1] - '0' == c.se) {
        ok = false;
        break;
      }
    }

    if (ok) drop(num);
  }

  drop(-1);
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void)
{
	char N[101];
	int  i,flag=0;
	scanf("%s", N);
	for (i = 0; i < 100; i++) {
		if (N[i] == 'C')
		{
			flag = 1; continue;
		}
		if(flag==1  &&N[i] == 'F')
		{
			printf("Yes"); return 0;
		}
	}
	printf("No");
	return 0;
}


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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  double ans = 0;
  int N,K;
  cin >> N >> K;

  for(int i = 1; i <= N; i++){
    double tmp = 1/(double)N;
    if(i >= K){

    } else { 
      int x = ceil(log2((double)K/(double)(i)));
      tmp *= pow(0.5, x);
    }
    ans += tmp;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int N = sc.nextInt();
      	if(N==0){
          System.out.println(String.valueOf(X));
          return;
        }
      
      List<Integer> forbits = new ArrayList<Integer>();
      for(int i=0;i<N;i++){
          forbits.add(sc.nextInt());
        }
      
      int diff = 0;
      int answer = 0;
      while(true){
        if(!forbits.contains(X-diff)){
          answer = X-diff;
          break;
        } else if(!forbits.contains(X+diff)){
          answer = X+diff;
          break;
        }
        diff++;
      }
      
      System.out.println(String.valueOf(answer));
    }
}

Measured memory_bytes: 35952
n = gets.to_i
p = gets.split.map(&:to_i)

for i in 1..n do
    if p[i-1] != i
        q = p[p[i-1]-1]
        p[p[i-1]-1] = p[i-1]
        p[i-1] = q
        break
    end
end
#p p
for i in 1..n do
    if p[i-1] != i
        puts "NO"
        exit
    end
end
puts "YES"     


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 
signed main()
{
    SPEED;
    int n,k,town,st;
    cin>>n>>k;
    vector<int> count;
    int a[n+1];
    for(int i=1;i<=n;++i)
        cin>>a[i];
    map<int,int> m;
    town=a[1];
    m[town]=1;
    count.pb(town);
    while(1)
    {
        town=a[town];
        if(m.find(town)!=m.end())
        {
            break;
        }
        count.pb(town);
        m[town]=1;
    }
    for(int i=0;i<(int)count.size();++i)
    {
        if(count[i]==town)
        {
            st=i;
            break;
        }
    }
    int sz=count.size();
    if(k>=st+1)
    {
        sz-=st; 
        k-=st;
        if(k%sz!=0)
            cout<<count[k%sz-1+st];
        else
            cout<<count[sz-1+st];
    }
    else
        cout<<count[k-1];
}

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

int Z = 0;
int cnt = 0;
int a = 0;
int b = 0;
vector<string> v;
void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for(int i = 0; i < n; i++)
        indexes[i] = i;
    do {
        f(indexes);
    } while(std::next_permutation(indexes, indexes + n));
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;

    Z = N;

    for(int i = 0; i < 2; i++) {
        string tmp;
        for(int j = 0; j < N; j++) {
            char x;
            cin >> x;
            tmp += {x};
        }
        v.push_back(tmp);
    }


    foreach_permutation(N, [](int *indexes) {
        string tmp;
        for(int x = 0; x < Z; x++) {
            // cout << indexes[x]+1;
            tmp += to_string(indexes[x] + 1);
        }
        if(tmp == v[0]){
            a = cnt;
        }
        if(tmp == v[1]){
            b = cnt;
        }
        cnt++;
    });
    cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
/*
 * ID: 0034
 * Problem: Railway lines
 */
#include <stdio.h>

int main(void)
{
    int d[10];
    double v1, v2;
    double cross_point;

    while (1) {
        if (scanf("%d,", d) <= 0)
            return 0;
        int i, total = d[0];
        for (i = 1; i < 10; i++) {
            scanf("%d,", d + i);
            total += d[i];
            //printf("d[%d] = %d\n", i, d[i]);
        }
        scanf("%lf,%lf", &v1, &v2);
        cross_point = total * v1 / (v1 + v2);
        //printf("v1, v2 = %lf, %lf, cross_point = %f\n", v1, v2, cross_point);

        i = 0;
        double distance = 0;
        do {
            distance += d[i++];
            //printf("distance %i = %f\n", i, distance);
        } while (distance < cross_point);

        printf("%d\n", i);
    }

    return 0;
}



Measured memory_bytes: 2028
#include <stdio.h>

int main(void)
{
	int A,B,K,p,i;
	int s[100];
	p = 0;
	scanf("%d %d %d",&A,&B,&K);
	for(i = 1;i <= A||i <= B;i++){
		if(A % i == 0 && B % i == 0){
			s[p] = i;
			p++;
		}
	}
	printf("%d\n",s[p - K]);
	return 0;
}

Measured memory_bytes: 1708
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    a, b, c, d = map(int, input().split())
    flag = -1
    while (a > 0 and c > 0):
        if flag == -1:
            c -= b
        else:
            a -= d
        flag *= - 1
    if flag == 1:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9492
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int h, w; cin>>h>>w;
    int k; cin>>k;
    string s[10];
    int ans=0;
    for(int i=0; i<h; i++) cin>>s[i];
    for(int i=0; i<(1<<h); i++){
        for(int j=0; j<(1<<w); j++){
            int cnt=0;
            for(int l=0; l<h; l++){
                for(int m=0; m<w; m++){
                    if(s[l][m]=='#' && (i&(1<<l))==0 && (j&(1<<m))==0) cnt++;
                }
            }
            if(cnt==k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

map<string, int> d;

int solve(string ini, string unlock)
{
  queue<string> que;
  d.clear();
  que.push(ini);
  d[ini] = 0;
  while(!que.empty()) {
    string s = que.front(); que.pop();
    if(s == unlock) break;
    string t = s; int idx = 0, rol = 0;
    while(t[idx] == unlock[idx]) idx++;
    while((t[idx]-'0'+rol) % 10 != unlock[idx]-'0') rol++;
    for(int i = idx; i < t.size(); i++) {
      t[i] = (t[i]-'0' + rol) % 10 + '0';
      if(d.count(t) != 1) {
	que.push(t);
	d[t] = d[s] + 1;
      }
    }
  }
  return d[unlock];
}

int main()
{
  int k;
  while(cin >> k, k) {
    string ini, unlock;
    cin >> ini >> unlock;
    cout << solve(ini, unlock) << endl;
  }
  return 0;
}

Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int n, ka[11] ,k, dp[50000][11];
 
int go(int i, int d){
      if(d > 5)return 1e9;
      if(i >= n && d <= 5)return i;
	  int &ret = dp[i][d];
	  if(ret + 1)return ret;
	  ret = 1e9;
	  for(int j = 0; j<10; ++j){
	     if(ka[j])continue;
	     if(!d && !j)continue;
	     ret = min(ret, go(i*10+j,d+1));
	  }
	  return ret;
} 
 
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 0; i<k; ++i){
	   int x;
	   scanf("%d", &x);
	   ka[x] = 1;
	}
	memset(dp,-1,sizeof dp);
	int an = go(0,0);
	cout << an;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#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 mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=998244353;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=2e5+5;
int nd[N],n,coor_x[N],coor_y[N];
ll ans;

struct point {
	int x,y,II,III,I,IV;
}p[N];
struct cmp1 {
	bool operator()(const point &a,const point &b) const {
		if (a.x==b.x) return a.y<b.y;
		return a.x<b.x;
	}
};
struct cmp2 {
	bool operator()(const point &a,const point &b) const {
		if (a.y==b.y) return a.x<b.x;
		return a.y<b.y;
	}
};

void modify(int p,int val) {
	for (int i=p;i<=n;i+=i&(-i)) nd[i]+=val;
}

int query(int p) {
	int res=0;
	for (int i=p;i;i-=i&(-i)) res+=nd[i];
	return res;
}

int main() {
	scanf("%d",&n);
	rep(i,0,n) {
		scanf("%d%d",&p[i].x,&p[i].y);
		coor_y[i]=p[i].y;
		coor_x[i]=p[i].x;
	}
	sort(coor_y,coor_y+n); sort(coor_x,coor_x+n); sort(p,p+n,cmp1());
	rep(i,0,n) {
		int pos=lower_bound(coor_y,coor_y+n,p[i].y)-coor_y+1;
		p[i].III=query(pos); p[i].II=i-p[i].III; modify(pos,1);
	}
	memset(nd,0,sizeof(nd)); sort(p,p+n,cmp2());
	rep(i,0,n) {
		int pos=lower_bound(coor_x,coor_x+n,p[i].x)-coor_x+1;
		p[i].III=query(pos); p[i].IV=i-p[i].III; modify(pos,1); p[i].I=n-1-p[i].II-p[i].III-p[i].IV;
	}
	rep(i,0,n) {
		ll a=powmod(2,p[i].I),b=powmod(2,p[i].II),c=powmod(2,p[i].III),d=powmod(2,p[i].IV),
		p1=(((a*c)%mod*(b-1))%mod*(d-1))%mod,p2=(((b*d)%mod*(a-1))%mod*(c-1))%mod,p3=((((a-1)*(b-1))%mod*(c-1))%mod*(d-1))%mod;
		ans=(ans+p1+p2-p3+mod)%mod;
	}
	ans=(ans+n*powmod(2,n-1))%mod;
	printf("%lld\n",ans);
}


Measured memory_bytes: 10792
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,A,B = map(int, input().split())
    AB = A+B
    ans = (N//AB) * A
    rem = N%AB
    if rem > A:
        ans += A
    else:
        ans += rem
    print(ans)

if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

typedef pair<int, int> P;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> M(H);
    rep(i, H) cin >> M[i];

    vector<vector<int>> dp(H, vector<int>(W, -1));
    dp[0][0] = 0;
    queue<P> q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
        P p = q.front();
        q.pop();
        rep(i, 4) {
            P np = make_pair(p.first + dx[i], p.second + dy[i]);
            if (np.first < 0 || W <= np.first || np.second < 0 || H <= np.second) continue;
            if (dp[np.second][np.first] != -1) continue;
            if (M[np.second][np.first] == '#') continue;
            dp[np.second][np.first] = dp[p.second][p.first] + 1;
            q.push(np);
        }
    }

    if (dp[H - 1][W - 1] == -1) {
        cout << -1 << endl;
        return 0;
    }

    int cnt = 0;
    rep(i, H) rep(j, W) if (M[i][j] == '#') cnt++;

    cout << H * W - 1 - dp[H - 1][W - 1] - cnt << endl;
}

Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())

answer = 10**18
for c in range(10**5+1):
  a = X-c
  b = Y-c
  cost = C*c*2
  cost += max(a,0)*A
  cost += max(b,0)*B
  if answer > cost:
    answer = cost
print(answer)


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

int main() {
  int N,A,B,C,D;
  cin >> N;
 
  A=N/1000;
  B=(N-1000*A)/100;
  C=(N-1000*A-100*B)/10;
  D=(N-1000*A-100*B-10*C) ; 
  if (A == B && B==C) {
    cout << "Yes" << endl;
  }

  else if (B == C && C == D) {
    cout << "Yes" << endl;
  }
    else   {
    cout << "No" << endl;
  }
  
}


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

vector<vector<int>> g(100001);
vector<int> ans(100001,-1);
map<pii,int> mp;

void dfs(int id){
    for(auto v:g[id]){
        if(ans[v]<0){
            ans[v]=ans[id]^(mp[make_pair(id,v)]%2);
            dfs(v);
        }
    }
}


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

    rep(i,n-1){
        int u,v,w;
        cin>>u>>v>>w;
        g[u].push_back(v);
        g[v].push_back(u);
        mp[make_pair(u,v)] = w;
        mp[make_pair(v,u)] = w;
    }

    ans[1]=0;
    dfs(1);
    
    REP(i,n){
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 23936
#include<bits/stdc++.h>
#define lli	long long int
#define pb push_back
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define rep(i,a,b)	for(i=a;i<b;i++)
using namespace std;
int main()
{
	char ch1,ch2,ch3;
	string s1,s2,s3,str;
    lli i,j,k,a,m,n,b,c,x,y,t,z,d,sum=0,ans=0,temp;
    cin >> n;
    ans=n/2;
    if(n%2!=0)	ans++;
    cout << ans << endl;
    
    
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

Measured memory_bytes: 3076
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

M = 0
for i in range(N):
    M += B[A[i] - 1]
    if i < N -1 :
        if A[i] + 1 == A[i + 1]:
            M += C[A[i] - 1]

print(M)

Measured memory_bytes: 3060
def main():
  n, w = [int(e) for e in input().split()]
  maxv = 10 ** 3 * n + 1
  t = [-1 for i in range(maxv)]
  t[0] = w
  cmaxv = 0
  for _ in range(n):
    nw, nv = [int(e) for e in input().split()]
    for i in range(cmaxv, -1, -1):
      if t[i] == -1:
        continue
      if t[i + nv] < t[i] - nw:
        t[i + nv] = t[i] - nw
        if cmaxv < i + nv:
          cmaxv = i + nv
  print(cmaxv)
main()

Measured memory_bytes: 5556
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
typedef unsigned long long ull;
typedef  long long ll;

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

	return gcd(b, a % b);
}
int main() {
	ll a, b, k;

	std::cin >> a >>b >>k;
	ll tmp, tmpb;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	tmpb = gcd(a, b);
	ll cntx = 0;
	tmp = tmpb;
	for (ll i = tmpb ; i > 0 ; --i) {
		if (tmpb%i == 0)
		{
			cntx += 1;
			tmp = i;
			if (cntx >= k)
			{
				tmp = i;
				break;
			}
		}
	}
	std::cout << tmp << std::endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#define N 100000
#define MAX (1<<31)-1
using namespace std;
int A[N], T[4*N];

void build(int l, int r, int k) {
    if (l == r) {
        T[k] = A[l];
        return;
    }
    int mid = (l + r) / 2;
    build(l, mid, k * 2);
    build(mid + 1, r, k * 2 + 1);
    T[k] = min(T[2 * k], T[2 * k + 1]);
}
void updata(int in, int data ,int l, int r ,int k) {
    if (l == r) {
        A[l] = T[k] = data;
        return;
    }
    int mid = (l + r) / 2;
    if (in <= mid) updata(in, data, l, mid, k * 2);
    else updata(in, data, mid + 1, r, k * 2 + 1);
    T[k] = min(T[2 * k], T[2 * k + 1]);
}
int find(int L, int R, int l, int r, int k) {
    if (L <= l && r <= R) return T[k];
    int mid = (l + r) / 2;
    int ans = MAX;
    if (mid >= L) ans = min(ans, find(L, R, l, mid, k * 2));
    if (mid < R) ans = min(ans, find(L, R, mid + 1, r, k * 2 + 1));
    return ans;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; i++)
        A[i] = MAX;
    build(0, n - 1, 1);
    int com, x, y;
    while (q--) {
        scanf("%d%d%d", &com, &x, &y);
        if (com == 0) updata(x, y, 0, n - 1, 1);
        else printf("%d\n", find(x, y, 0, n - 1, 1));
    }
    return 0;
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  vector<int> hs;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    hs.push_back(h);
  }

  sort(hs.begin(), hs.end());
  int ans = 1e+9+1;;
  for (int i = 0; i <= N - K; i++){
    ans = min(ans, hs[i + K - 1] - hs[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 892
#include <cstdio>
#include <iostream>
using namespace std;
#define mod 1000000007
int main(){
  int n;
  cin >> n;
  long long a = 1;
  for (int i = 1; i <= n; i++) {
    a *= i;
    a %= mod;
  }
  cout << a << endl;
  return 0;
}


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

using namespace std;

const int NIL = -1;     //不存在的点

struct node
{
    int parent;
    int left;
    int right;
    node()
    {
        parent = NIL;
        left = NIL;
        right = NIL;
    }
};

class LCRS
{
    vector<node> tree;

    public:

    int getDepth(int u)
    {
        int d=0;
        while (tree[u].parent != NIL)
        {
            u=tree[u].parent;       //获取父亲
            ++d;
        }
        return d;
    }

    string getType(int u)
    {
        if(tree[u].parent==NIL)
        {
            return "root";
        }
        else if(tree[u].left==NIL)
        {
            return "leaf";
        }
        else 
        {
            return "internal node";
        }
    }

    vector<int> getChildren(int u)
    {
        vector<int> children;
        int c=tree[u].left;
        while (c!=NIL)
        {
            children.push_back(c);
            c=tree[c].right;    //获取右兄弟
        }
        return children;
    }

    void fillTree()
    {
        int n;
        cin >> n;
        int nodeCount = n;
        tree.assign(n, node());
        while (nodeCount--)
        {
            int pNodeId;
            cin >> pNodeId;
            int k;
            cin >> k;
            int i = 0;
            int preId = 0;

            while (k--)
            {
                int cNodeId;
                cin >> cNodeId;

                tree[cNodeId].parent = pNodeId;
                //tree[pNodeId].children.push_back(cNodeId);

                if (i == 0)
                {
                    tree[pNodeId].left = cNodeId;
                }
                else
                {
                    tree[preId].right = cNodeId;
                }
                preId = cNodeId;
                ++i;
            }
        }
    }


    void printTree()
    {
        int size1=tree.size();
        for (int i = 0; i <= size1 - 1; ++i)
        {
            cout << "node " << i
            << ": parent = " << tree[i].parent
            << ", depth = " << getDepth(i)
            << ", " << getType(i) << ", [";

            vector<int> children = getChildren(i);
            int n1 = children.size();
            for (int j = 0; j <= n1 - 1; ++j)
            {
                cout << children[j];
                if (j != n1 - 1)
                {
                    cout << ", ";
                }
            }            
            cout << "]\n";
        }
    }    
};



int main()
{
    //freopen("treeLCRS.in", "r", stdin);
    LCRS lcrsTree;
    lcrsTree.fillTree();
    lcrsTree.printTree();

    return 0;
}



Measured memory_bytes: 4628
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int N;
        while(true) {
                cin >> N;
                if(N==0) break;
                vector<pair<int,int> > rw(N);
                rep(i,N) cin >> rw[i].first >> rw[i].second;
                sort(rw.begin(),rw.end(),greater<pair<int,int> >());
                int sum = 0;
                rep(i,N-1) sum +=rw[i+1].first;

                int ans = 0;
                rep(i,N) ans +=rw[i].first + rw[i].second;


                if(rw[0].first > sum) {
                        int W = rw[0].first - sum;
                        int d[1010][1010]={};
                        REP(i,1,N){
                                rep(j,W+1){
                                        if(j < rw[i].second) d[i][j] = d[i-1][j];
                                        else{
                                                d[i][j] = max(d[i-1][j], (rw[i].second + d[i-1][j-(rw[i].second)]));
                                        }
                                }
                        }
                        int space = W - d[N-1][W];
                        ans += space;
                }
                cout << ans << endl;
        }

        return 0;
}



Measured memory_bytes: 7064
#include<stdio.h>
int n;
int p[100][100]={0};
int M[100]={0};
int k;
int l[100]={0};
int main(void){
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        int info[100][100]={0};
        for(int i=0;i<n;i++){
            scanf("%d",&M[i]);
            for(int j=0;j<M[i];j++){
                scanf("%d",&p[i][j]);
                info[i][p[i][j]]=1;
            }
        }
        int count=0;
        int index=0;
        scanf("%d",&k);
        for(int i=0;i<k;i++) scanf("%d",&l[i]);
        for(int i=0;i<n;i++){
            int flag=1;
            for(int j=0;j<k;j++){
                if(info[i][l[j]]==0){
                    flag=0; break;
                }
            }
            if(flag){
                count++;
                index=i;
            }
            if(count==2) break;
        }
        if(count==1) printf("%d\n",index+1);
        else printf("-1\n");
    }
}



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

int main(){
  string S, T;
  cin >> S >> T;
  int ans = 0;
  rep(i, S.size()) if (S[i] != T[i]) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 3908
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007



int main() {
  ll n;
  cin>>n;
  vector<ll> va;
  vector<ll> vb;
  rep(i,0,n){
    ll a,b;
    cin>>a>>b;
    va.pb(a);
    vb.pb(b);
  }
  reverse(all(va));
  reverse(all(vb));
  ll ans = 0;
  rep(i,0,va.sz){
    ll a = va[i]+ans;
    ll b = vb[i];
    if(a%b!=0){
      ans += (b-a%b);
    }
  }
  printf("%lld\n", ans);
  return 0;
}





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

#define ll long long int

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
#define trace3(x,y,z) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;
#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(),(v).end()

using namespace std;
///////////////////////////////////////////////////////

const int N = 1e5+5;

int n;
int a[N];
map<int,int> M;
vector<int> vec;

int main()
{
	fast_io;

	cin>>n;
	FOR(i,1,n){
		cin>>a[i];
		M[a[i]]++;
	}

	for(auto p:M){
		if(p.S >= 2){
			vec.pb(p.F);
		}

		if(p.S>=4){
			vec.pb(p.F);
		}
	}

	sort(all(vec));

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

	cout<<1LL*vec[vec.size()-1]*vec[vec.size()-2]<<endl;

	return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  vector<int> aa;
  aa=a;
  sort(aa.begin(),aa.end());
  for(int i=0;i<n;i++){
    if(a[i]!=aa[n-1]){
      cout<<aa[n-1]<<endl;
    }else{
      cout<<aa[n-2]<<endl;
    }
  }
}

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

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

Measured memory_bytes: 3648
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector<ll> v1;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/

int main()
{
	cin >> n >> k >> h;
	ans = max(k, h) - min(k, h) - n;
	if(ans<0)
	{
		cout << 0 << endl;
	}else
	{
		cout << ans << endl;
	}
}

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

using namespace std;
int n,k,q;
int hotel[200005];
int jump[200005][20];

/* Phan chuan bi LCA */
void pre_process()
{
    for(int i=1;i<=n;i++)
    {
        int p = upper_bound(hotel,hotel+n+2,hotel[i]+k) - hotel ;
        jump[i][0] = p-1;
    }

    for(int j=1;j<20;j++)
    {
        for(int i=1;i<=n;i++)
        {
            if(jump[i][j-1]!=-1)
                jump[i][j] = jump[jump[i][j-1]][j-1];
        }
    }
}

/* Phan tinh LCA */
int solve(int u,int v)
{
    if(u==v)
        return 0;
    int ans = 0;
    for(int i=17;i>=0;i--)
    {
        if(jump[u][i]<v)
        {
            u = jump[u][i];
            ans+=(1<<i);
        }
    }

    return ans+1;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n;

    hotel[n+1] = 2e9;
    memset(jump,-1,sizeof jump);

    for(int i=1;i<=n;i++)
    {
        cin>>hotel[i];
    }
    cin>>k;
    pre_process();
    cin>>q;

    while(q--)
    {
        int u,v;
        cin>>u>>v;
        if(u>v)
            swap(u,v);

        cout<<solve(u,v)<<'\n';
    }

}


Measured memory_bytes: 17280
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,cnt[55][55]={};
  char c[55][55]={};
  cin >> h >> w;
  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      cin >> c[i][j];
    }
  }
  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      if(c[i][j]=='#') {
        cout << '#';
      }
      else {
        cout << (c[i-1][j]=='#')+(c[i-1][j-1]=='#')+(c[i-1][j+1]=='#')+(c[i][j-1]=='#')+(c[i][j+1]=='#')+(c[i+1][j-1]=='#')+(c[i+1][j]=='#')+(c[i+1][j+1]=='#');
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
    std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
    
    int N;
    std::cin >> N;
    int max = -1;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int H;
        std::cin >> H;
        if (H >= max) {
            ++ans;
            max = H;
        }
    }
    std::cout << ans << std::endl;

}

Measured memory_bytes: 256
//package gfg;
import java.io.*;


public class Main {

	public static void main(String[] args) throws Exception {
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	int t=Integer.parseInt(br.readLine().trim());
	int res=(t*t*t);
	int r=res;
	for(int i=0;i<2;i++) {
		res=(res/t);
		r+=res;
	}
	System.out.println(r);
	
	
	}
	
	
	
	
	
	

}


Measured memory_bytes: 32416
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

typedef long long ll;


vector <ll> primes;
ll max_prime;

bool is_prime(ll n) {
    ll m;
    int i;
    bool result = true;

    m = int(sqrt(n));

    i = 0;
    while (primes[i] <= m) {
        if (n % primes[i] == 0) {
            // cout << n << " % " << primes[i] << " == 0" << endl;
            result = false;
            break;
        }
        i++;
    }

    return result;
}


void calc_primes(ll n) {
    ll i;

    primes.push_back(2);
    for (i = 3; i <= n; i += 2) {
        if (is_prime(i))
            primes.push_back(i);
    }
}

map <ll,ll> decomp(ll n) {
    map <ll,ll> prime_count;

    ll m = n;
    int i = 0;
    int n_primes = primes.size();

    while (i < n_primes && primes[i] <= m) {
        if (m % primes[i] == 0) {
            m /= primes[i];

            auto itr = prime_count.find(primes[i]);
            if (itr != prime_count.end()) {
                (itr->second) +=1;
            }
            else {
                prime_count.insert(pair<ll, ll>{primes[i],1});
            }
        }
        else {
            i++;
        }
    }
    if (m != 1) {
        prime_count.insert(pair<ll, ll>{m, 1}); // for n=prime
    }

    return prime_count;
}

int main()
{
    ll N;
    cin >> N;

    if (N == 1) {
        cout << 0 << endl;
        exit(0);
    }

    calc_primes(ll(sqrt(N)));
    map <ll,ll> prime_count = decomp(N);


    ll n = 0;
    for (auto itr : prime_count) {
        //cout << itr.first << ":" << itr.second << " ";

        ll m = itr.second;
        ll i = 1;
        while (m >= i) {
            n++;

            m -= i;
            i++;
        }

    }
    cout << n << endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
int main(){
  int n;
  cin >> n;
  set<int>s;
  rep(i,n){
    int tmp;
    cin >> tmp;
    s.insert(tmp);
  }
  int ans = s.size();
  if((n - ans) % 2 == 0)cout << ans << endl;
  else cout << ans - 1 << endl;
  return 0;
}

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

int main(){
  int N,C,K;
    cin>>N>>C>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    int a=A[0],cnt=1,ans=1;
    for(int i=1;i<N;i++){
        if(a+K>=A[i]&&cnt<C) cnt++;
        else{
            cnt=1;
            a=A[i];
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl "\n"
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 uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n; 

  vector<ll> p(n);
  int cnt=0;
  rep(i,n){
    cin>>p[i];
    if(p[i]<0) cnt++;
    p[i]=abs(p[i]);
  }

  sort(all(p));

  ll ans=0;
  if(cnt%2==0){
    rep(i,n){
      ans+=p[i];
    }
  }
  else {
    repo(i,n){
      ans+=p[i];
    }
    ans-=p[0];
  }


  cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;

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

  ll h, w;
  cin >> h >> w;
  vector < string > s(h);
  for(int i = 0; i < h; i++) cin >> s[i];
  vector < vector < ll > > d(h, vector < ll > (w, 1e18));
  queue < pair < ll, ll > > q;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#'){
        d[i][j] = 0;
        q.push({i, j});
      }
    }
  }

  ll mx = 0;
  vector < ll > dx = {1, 0, -1, 0};
  vector < ll > dy = {0, -1, 0, 1};
  while(!q.empty()){
    int x = q.front().first, y = q.front().second;
    q.pop();
    for(int i = 0; i < 4; i++){
      int x1 = x + dx[i], y1 = y + dy[i];
      if(x1 >= 0 && x1 < h && y1 >= 0 && y1 < w && s[x1][y1] == '.'){
        if(d[x1][y1] > d[x][y] + 1){
          d[x1][y1] = d[x][y] + 1;
          mx = max(mx, d[x1][y1]);
          q.push({x1, y1});
        }
      }
    }
  }

  cout << mx << endl;
}


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

int main(){
    int N;
    double total;
  	total=0;
    cin >> N ;
  	double x;
    string u;
    for(int i = 0;i < N ;i++){
        cin >> x >> u;
        if(u=="JPY"){
            total += x;
        }else{
            total += x*380000;
        }
    }
    cout << total <<endl;
    
}

Measured memory_bytes: 256
/******* 困ったと時の神頼み！！！*******/

#include <bits/stdc++.h>

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, sum = 0;
  cin >> n;
  vector<int> A(n + 5), a(n + 5, 0);
  rep(i, 0, n + 1) cin >> A[i], sum += A[i];

  int ans = 0;
  if (n == 0 && A[0] == 1) {
    cout << 1 << '\n';
    return 0;
  } else {
    rep(i, 0, n + 1) {
      // cout << sum << ' ';
      if (a[i] * 2 < A[i]) {
        cout << "-1\n";
        return 0;
      } else if (i == 0) {
        a[i] = 1;
        ++ans;
        sum -= A[i];
        a[i + 1] = a[i];
      } else {
        a[i] = min(sum, a[i] * 2);
        ans += a[i];
        a[i] -= A[i];
        // cout << a[i] << ' ';
        sum -= A[i];
        a[i + 1] = a[i];
        // cout << a[i + 1] << ' ';
        // cout << ans << '\n';
      }
    }
  }

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

Measured memory_bytes: 4768