akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
ll n,dp[404][404][404];
struct node{
	ll A,B;
}x[1010]; 
inline bool cmp(node a,node b){
	return a.B<b.B;
}
inline ll fast_pow(ll a,ll b,ll p){
	ll t=1;
	while (b){
		if (b&1ll) t=t*a%p;
		b>>=1ll;a=a*a%p;
	}
	return t;
}
ll sumA[1010],sumB[1010],fac[1010],inv[1010],_inv[1010],pw[404][404];
signed main(){
	n=read();
	for (int i=1;i<=n;i++){
		x[i].A=read(),x[i].B=read();
	}
	fac[0]=inv[0]=inv[1]=_inv[0]=1;
	for (ll i=1;i<=400;i++) fac[i]=i*fac[i-1]%ljc;
	for (ll i=2;i<=400;i++) inv[i]=(ljc-(ljc/i)*inv[ljc%i]%ljc)%ljc;
	for (ll i=1;i<=400;i++) _inv[i]=_inv[i-1]*inv[i]%ljc;
	sort(x+1,x+1+n,cmp);
	for (int i=1;i<=n;i++){
		sumA[i]=sumA[i-1]+x[i].A;
		sumB[i]=sumB[i-1]+x[i].B-1;
	}
	for (int i=1;i<=n;i++){
		pw[i][0]=1;
		pw[i][1]=x[i].A%ljc;
		for (int j=2;j<=400;j++){
			pw[i][j]=pw[i][j-1]*pw[i][1]%ljc;
		}
	}
	dp[0][0][0]=ljc-1;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=sumA[i-1];j++){
			for (int k=0;k<=sumB[i-1];k++){
				dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k])%ljc;
				for (int l=0;l<x[i].B;l++){
					dp[i][j+x[i].A][k+l]=(dp[i][j+x[i].A][k+l]+ljc-dp[i-1][j][k]*pw[i][l]%ljc*_inv[l]%ljc)%ljc;
				}
			}
		}
	}
	ll _=0;
	for (int i=0;i<=sumA[n];i++){
		for (int j=0;j<=sumB[n];j++){
			_=(_+fac[j]*dp[n][i][j]%ljc*sumA[n]%ljc*fast_pow(i,ljc-2,ljc)%ljc*fast_pow(i,ljc-1-j,ljc)%ljc)%ljc;
		}
	}
	cout<<_;
    return 0;
}


Measured memory_bytes: 259672
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)

using namespace std;

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

	int N;
	int s;
    cin >> N >> s;
	s = s/1000;
	int x = -1, y = -1, z = -1;
	for (int i = 0; i < N+1; i++)
	{
		for (int j = 0; i+j < N+1; j++)
		{
			if(s-10*i-5*j!=N-i-j) continue;
			else {
				x=i, y=j, z=N-i-j;
			}
		}
		
	}
	cout << x << " " << y << " " << z << endl;
	
}

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

int main(void) {
	char s[200001], *a, *z;
	scanf("%s", &s);
	
	a = strchr(s, (int)'A');
	z = strrchr(s, (int)'Z');
	
	printf("%d\n", z-a+1);
	
	return 0;
}

Measured memory_bytes: 384
// 2020.3.1実施 ABC 157 e問題
/* 解説後の再作成
 * 26文字分の「set」を作り，それぞれで出てくる位置を管理する
 * ある範囲の種類 = 文字ごとにlower_boundを取り，範囲内かどうかで「あるか」を判断すれば，O(log n)で可能となる
 */

#include<iostream>
#include<string>
#include<vector>
#include<set>
using namespace std;
int main(){
  string s;
  int n, q;
  cin >> n; // 文字数
  cin >> s; // 初期文字列
  cin >> q; // クエリ数
  vector<int> res; // クエリ結果保存
  // setを作成
  vector<set<int>> v(26);
  for(int i=0;i<n;i++){
    v[s[i]-'a'].insert(i);
  }
  // クエリ入力しつつ処理
  for(int i=0;i<q;i++){
    int com;
    cin >> com;
    if(com==1){
      //文字変更
      int j;
      char c;
      cin >> j >> c;
      v[s[j-1]-'a'].erase(j-1);
      v[c-'a'].insert(j-1);
      s[j-1] = c;
    } else if(com==2){
      //範囲内の文字種類をカウント
      int l, r, cnt=0;
      cin >> l >> r;
      for(int j=0;j<26;j++){
        set<int>::iterator it = v[j].lower_bound(l-1);
        if( it != v[j].end() ){
          if( *it <= r-1 ){
            cnt++;
          }
        }
      }
      res.push_back(cnt);
    }
  }
  for(const auto& e : res){
    cout << e << endl;
  }
  return 0;
}


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

int main(){
  int n;  cin >> n;
  vector<long long>a(n);  for(int i=0;i<n;i++)  cin >> a.at(i);
  vector<long long>b(n);  for(int i=0;i<n;i++)  cin >> b.at(i);
  vector<long long>c(n);  for(int i=0;i<n;i++)  cin >> c.at(i);
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());

  long long ans = 0;
  for(int i=0;i<n;i++){
    auto Iter = lower_bound(a.begin(),a.end(),b.at(i));
    long long count_a = Iter - a.begin();

    Iter = upper_bound(c.begin(),c.end(),b.at(i));
    long long count_c = n - (Iter - c.begin());

    ans += count_a * count_c;
  }
  cout << ans << endl;
}

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

int main()
{
	while(1)
	{
		int d;
		if(EOF == scanf("%d",&d))
		{
			break;
		}
		int now = 0;
		for(int i = d; i <= 600 - d; i += d)
		{
			now += i * i * d;
		}
		printf("%d\n",now);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n;
  cin>>n;
  vector<long long int> hoge(n);
  for(long long int i=0; i<n; i++){
    cin>>hoge.at(i);
  }
  sort(hoge.begin(),hoge.end());
  hoge.at(n-1)=hoge.at(n-1)/2;
  long long int ans=0;
  for(long long int i=0; i<n; i++){
    ans+=hoge.at(i);
  }
  cout<<ans<<endl;
}

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

int main(){
    int n;
    vector<int> v;
    
    cin >> n;
    v.reserve(n);
    for(int i = 0 ; i < n ; i++) cin >> v[i];
    for(int i = n-1 ; i >= 0 ; i--){
        if(i == 0) cout << v[i] << endl;
        else cout << v[i] << ' ';
    }

    return 0;
}

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

using namespace std;

int main()
{
    int N; cin >> N;
    vector<int> v;
    v.push_back(0);

    for(int i=0;i<N;++i)
    {
        int t;cin >>t;
        v.push_back(t);
    }
    vector<int> w(v);
    sort(w.begin(),w.end());

    for(int j=1;j<=N;++j)
    {
        if(v[j]<=w[N/2]) cout << w[N/2 + 1]<<endl;
        else cout << w[N/2] << endl;
    }
    return 0;
}

Measured memory_bytes: 3828
n = int(input())
n = str(n)
# nの二桁目と三桁目が同じで、それが一桁目か四桁目がと同じならYes
if n[1] == n[2]:
    if n[0] == n[1] or n[2] == n[3]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9040
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; 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(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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;
}

int main()
{
  int H, N;
  cin >> H >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i] >> B[i];

  vector<vector<long long>> dp(N + 1, vector<long long>(H + 1, INF));
  dp[0][0] = 0;
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j <= H; ++j)
    {
      // 一つ前の状態(何もしない)と行動する場合に引いて足す
      dp[i + 1][j] = min(dp[i][j], dp[i + 1][max(0, j - A[i])] + B[i]);
    }
  }
  cout << dp[N][H] << endl;
}


Measured memory_bytes: 78592
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll X;

int main()
{
  std::cin >> X;

  std::cout << (X>=30 ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
  long long int arr[5];
  long long int ans;
  for(long long int i=0;i<5;i++){
    cin>>arr[i];
    if(arr[i] == 0){
      ans = i+1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <utility>

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    int A[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                count++;
            }
        }
    }
    for (int i = 0; i < N; i++) {
        if (i != 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n%d\n", count);
}


Measured memory_bytes: 2596
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

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

    int ans = a + b;
    ans = min(ans, min(a+c, b+c));

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

int main(){
    long double L;
    cin>>L;
    L=L*L*L;
    L/=27;
    cout<<setprecision(15)<<L<<endl;
}



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

#define int long long int

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif
//!
const int maxr = 2e5+5;
int pref[maxr],suff[maxr];
const int M = 1e9+7;


int32_t main()
{
	GO
	//fioe();
	int n,k;
	cin>>n>>k;
	for(int i=0;i<=n;i++)
		pref[i] = suff[i] = i;
	for(int i=1;i<=n;i++){
		pref[i] += pref[i-1];
		pref[i] %= M;
	}
	for(int i=n-1;i>=0;i--){
		suff[i] += suff[i+1];
		suff[i] %= M;
	}

	int ans = 0;
	for(int i=k-1;i<=n;i++){
		ans += (suff[n-i] - pref[i] + 1 + 4*M)%M;
		ans %= M;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6704
#include <iostream>
#include <string>
using namespace std;
int main(){
	int N,s[100],f[100],ans=0,b=0;
	int k=0,q=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>s[i];
	}
	for(int i=0;i<N;i++){
		ans+=s[i];
	}
	for(int i=0;i<N;i++){
		if(s[i]%10==0){
			b=b+1;
		}
		if(b==N){
			cout<<0<<endl;
			q=1;
		}
	}
	if(ans%10==0 && q==0){
		for(int i=0;i<N;i++){
			f[i]=ans-s[i];
			if(k<f[i] && s[i]%10!=0)k=f[i];	
		}
		cout<<k<<endl;
	}
	if(ans%10!=0 && q==0){
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;

#define MAX 1000000000000000000

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
        if(a.at(i)==0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    long long answer=1;
    for (int i = 0; i < n; i++)
    {
        if (a.at(i)<=MAX/answer)
        {
            answer*=a.at(i);
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << answer << endl;
    
}


Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  string S;
  cin >> S;
  rep(i,S.size()){
    if((i+1)%2==1 && S[i]=='L'){
      cout << "No" << endl;
      return 0;
    }
    if((i+1)%2==0 && S[i]=='R'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int main(){
  int n, d;
  cin >> n >> d;
  
  int x[n][d];
  for(int i=0; i<n; ++i){
    for(int j=0; j<d; ++j){
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for(int i=0; i<n; ++i){
    for(int j=i+1; j<n; ++j){
    int res=0;
      for(int k=0; k<d; ++k){
        int diff = abs(x[i][k] - x[j][k]);
        res += diff*diff;
      }
      bool flag = false;
      for(int k=0; k<=res; ++k){
        if(k*k == res) flag = true;
      }
    if(flag) ans++;
    }
  }

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

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

void write(vector<vector<int> >& o){
	cout << "Yes" << endl;
	cout << o.size() << endl;
	for(int i=0;i<o.size();i++){
		cout << o[i].size();
		for(int j=0;j<o[i].size();j++){
			cout << " " << o[i][j];
		}
		cout << endl;
	}
}
int main() {
	int N;
	cin >> N;
	vector<vector<int> > ret;
	ret.push_back({1});
	ret.push_back({1});
	if(N==1){
		write(ret);
		return 0;
	}
	int i=1;
	int d=2;
	while(i+d<=N){
		ret.push_back({});
		for(int j=0;j<d;j++){
			ret[j].push_back(i+j+1);
			ret.back().push_back(i+j+1);
		}
		i+=d;
		d++;
		if(i==N){
			write(ret);
			return 0;
		}
	}
	cout << "No" << endl;


	return 0;
}



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

int main() {
  vector<int> vec;
  int K;
  cin >> K;
  K--;
  vec = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  cout << vec.at(K) << endl;
}


Measured memory_bytes: 256
m,d = map(int,input().split())
ans = 0
if d < 22:
    print(ans)
    exit(0)
for i in range(22,d+1,1):
    #print(i)
    for j in range(1,m+1):
        if (i//10)*(i%10) == j:
            if (i%10) >= 2:
                ans +=1
print(ans)


Measured memory_bytes: 2940
from itertools import combinations
h, w, k = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(h)]

ans = 10 ** 9
# Hが10なので横の割り方は決め打ち、縦は貪欲にKを見る。最小の数が答え。

for i in range(2 ** (h - 1)):
  # 割った後の各かたまりの白チョコ数を入れる箱
  box = [[0] * w]
  # bcnt: 横に割ったかたまりの番地を数える数
  bcnt = 0
  box[bcnt] = [s + b for s, b in zip(S[0], box[bcnt])]

  for j in range(1, h):
    if (i >> (j-1)) & 1:
      bcnt += 1
      box.append([0] * w)
    box[bcnt] = [s + b for s, b in zip(S[j], box[bcnt])]
  
  # kよりも大きな区間が一つでもあればNG
  if not all([all([i <= k for i in b]) for b in box]):
    continue

  cutcnt = len(box) - 1
  cnt = [0] * len(box)
  for m in range(w):
    for n in range(len(box)):
      cnt[n] += box[n][m]
    if any([c > k for c in cnt]):
      cutcnt += 1
      for n in range(len(box)):
        cnt[n] = box[n][m]
  ans = min(ans, cutcnt)

print(ans)
 

Measured memory_bytes: 3316
#include<stdio.h>

int A[2000],m[2000],n;
int solve(int i,int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  return solve(i+1,m) || solve(i+1,m-A[i]);
}
int main(){
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&m[i]);
  for(i=0;i<q;i++){
  if(solve(0,m[i])) printf("yes\n");
  else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <stdio.h>
#include <string>
#include <fstream>
#include <string.h>
using namespace std;
int main(){
  string s, t;

  cin >> s;
  cin >> t;

  for(int i = 0; i < s.size(); i++){
      cout << s[i];
      if( (i==s.size()-1) && s.size()!=t.size() )break;
      cout << t[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input()
s="SW"
for d in range(2):
    for c in range(2):
        k=s[d]+s[c]
        for i in range(2,n+2):
            if k[i-1]=="S":
                if a[(i-1)%n]=="o":
                    k+=k[i-2]
                else:
                    k+=("W" if k[i-2]=="S" else "S")
            else:
                if a[(i-1)%n]=="o":
                    k+=("W" if k[i-2]=="S" else "S")
                else:
                    k+=k[i-2]
        else:
            if k[0]==k[-2] and k[1]==k[-1]:
                print(k[:-2])
                exit()
else:
    print(-1)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail
{
  template <typename T, std::size_t NDIMS>
  struct vector_builder
  {
    using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
      if (!dims.empty())
        dims.pop_back();
      return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
    }
  };

  template <typename T>
  struct vector_builder<T, 1>
  {
    using type = std::vector<T>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      return type(dims.empty() ? 0 : dims.back(), v);
    }
  };
} // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T &v, SIZE_T... dims)
{
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long X)
{
  LL a = X / 500;
  LL ans = a * 1000 + (X % 500) / 5 * 5;
  cout << ans << endl;
}

int main()
{
  cout << setprecision(10);
  long long X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}


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

#define MAX_V 10000

int V;
vector<int> G[MAX_V], rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void add_edge(int from, int to) {
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(int v) {
  used[v] = true;
  for(unsigned i=0; i<G[v].size(); i++) {
	if(!used[G[v][i]]) dfs(G[v][i]);
  }
  vs.push_back(v);
}

void rdfs(int v, int k) {
  used[v] = true;
  cmp[v] = k;
  for(unsigned i=0; i<rG[v].size(); i++) {
	if(!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
}

int scc() {
  memset(used, 0, sizeof(used));
  vs.clear();
  for(int v = 0; v < V; v++) {
	if(!used[v]) dfs(v);
  }
  memset(used, 0, sizeof(used));
  int k = 0;
  for(int i=vs.size()-1; i>=0; i--) {
	if(!used[vs[i]]) rdfs(vs[i], k++);
  }
  return k;
}

int main() {
  int E, s, t;
  cin >> V >> E;
  while(E--) {
	cin >> s >> t;
	add_edge(s, t);
  }
  
  scc();
  
  int q, u, v;
  cin >> q;
  while(q--) {
	cin >> u >> v;
	cout << ( cmp[u] == cmp[v] ) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2784
while 1:
  n=input()+1
  if n==1: break
  x=[]
  y=[0]*n
  for _ in range(n-1):
    a=map(int,raw_input().split(' '))
    a.append(sum(a))
    s=""
    for i in range(n):
      y[i]+=a[i]
      s+=str(a[i]).rjust(5)
    print s
  print "".join([str(e).rjust(5) for e in y])

Measured memory_bytes: 4228
#include <iostream>
using namespace std;
int main() {
    string word[100];
    int n;
    int m = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> word[i];
    }
    for (int j = 1; j < n; ++j) {

        for (int i = 0; i < j; ++i) {
            if (word[j] == word[i]){
                cout<< "No";
                m = 1;
                break;
            }
        }
        if (m == 1)break;
        char endword = word[j -1].back();
        char frontword = word[j].front();
        if (endword != frontword){
            cout << "No";
            m = 1;
            break;
        }
        if (m == 1)break;
    }
    if (m == 0){
        cout << "Yes";
    }
    return 0;
}

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

namespace AtCoder.ABC043
{
    class ProblemC
    {
        static void Main()
        {
            ReadLine();
            var values = ReadIntArray();
            var avg = values.Average();
            var dst = avg >= 0 ? (int)(avg + 0.5) : (int)(avg - 0.5);
            Console.WriteLine(values.Sum(v => (v - dst) * (v - dst)));
        }

        static IEnumerable<int> EnumerateDigt(int value)
        {
            while (value > 0)
            {
                yield return value % 10;
                value /= 10;
            }
        }

        public static string ReadLine() => Console.ReadLine();

        public static int ReadInt() => int.Parse(ReadLine());

        public static int[] ReadIntArray() => ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
    }
}


Measured memory_bytes: 13396
#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];// i+1番目が消えて、a[i]が点く。1-indexed
    int x = 0;//今点いているボタンの番号。0-indexed
    int count = -1;//操作を何回行ったか。はじめに-1にしておくと便利
    for(int i = 0; i < n; i++) {//n回操作を行って2が出なかったら、もう2にはならない
        x = a[x]-1;//-1
        if(x == 1) {//0-indexedなので、2じゃない
            count = i+1;//操作はi+1回
            break;//これが最初回の操作なのでbreak;
        }
    }
    cout << count << endl;
}

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

int main () {

    long long n, m, d;

    scanf("%lld %lld %lld", &n, &m, &d);

    double ans = 0.0;

    if (d == 0) ans = (m - 1) / (double)n;
    else ans = (m - 1) * 2 * (n - d) / (double)(n * n);

    printf("%.8f\n", ans);

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            if (n <= 104) WriteLine(0);
            else if (n <= 134) WriteLine(1);
            else if (n <= 164) WriteLine(2);
            else if (n <= 188) WriteLine(3);
            else if (n <= 194) WriteLine(4);
            else if (n <= 200) WriteLine(5);
        }
        

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


Measured memory_bytes: 13140
class TCastle
  def solve
    while true
      n    = gets.chomp.to_i
      return if n == 0
      cnt = Array.new (7) {0}
      n.times do
        x = gets.chomp.to_i
        case x
        when 0..9
          cnt[0] += 1
        when 10..19
          cnt[1] += 1
        when 20..29
          cnt[2] += 1
        when 30..39
          cnt[3] += 1
        when 40..49
          cnt[4] += 1
        when 50..59
          cnt[5] += 1
        else
          cnt[6] += 1
        end
      end
      cnt.map{|i| puts i}
    end
  end
end

if $0 == __FILE__
  TCastle.new.solve
end

Measured memory_bytes: 8752
#include<stdio.h>

int main(void)
{
	int n,x,m,min,i;
	scanf("%d%d%d",&n,&x,&m);
	min=m;
	x-=m;
	for(i=0;i<n-1;i++){
		scanf("%d",&m);
		if(m<min)
			min=m;
		x-=m;
	}
	
	printf("%d",n+x/min);
	return 0;
}

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

int main() {
    string s,t; cin >> s >> t;
    vector<string> ans;
    int l = s.size()-t.size()+1;
    for(int i = 0; i < max(0, l); i ++) {//sの可能性があるところまで
        string tmp = s;
        for(int j = 0; j < t.length(); j ++) {//tを一つずつ比べる
            if(i+j>s.size()-1) break;//
            if(tmp[i+j]=='?' || tmp[i+j]==t[j]) tmp[i+j] = t[j];
            else break;
            if(j==t.length()-1) {
                for(int k = 0; k < tmp.length(); k ++) {
                    if(tmp[k]=='?') tmp[k] = 'a';
                }
                ans.push_back(tmp);
            }
        }
    }
    sort(ans.begin(), ans.end());
    cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
    return 0;
}

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

/// Defining variable types.
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

/// Defining usable key words
#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

/// Defining constant variables.
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

/// Defining some useful lines.
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);


/// Code of debugger.
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

const int mx=1e5+123;
int n;
int dp[mx][4];
int h[mx][4];

int solve(int i,int x)
{
    if(i>n)
        return 0;
    if(dp[i][x]!=-1)
        return dp[i][x];

        int ret=0;

    for(int j=1;j<=3;j++)
    {
        if(j!=x)
        {
            ret=max(ret,h[i][j]+solve(i+1,j));
        }
    }



    return  dp[i][x]=ret;
}


int main()
{
    optimize();

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>h[i][1]>>h[i][2]>>h[i][3];
    }

    mem(dp,-1);

    cout<<solve(1,0)<<endl;

    return 0;
}


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

int main(void){
  ll a,b,c,k; cin >> a >> b >> c >> k;
  ll ans=0;
  if(k<a) for(ll i = 1;i<=k;i++) ans+=1;
  if(k>=a) ans = a;
  
  if(k>a+b){
    for(ll i=1;i<=k-(a+b);i++) ans-=1;
  }

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


Measured memory_bytes: 3624
#include<iostream>

int main(){
  int num;
  int a[4] = {1000,100, 10, 1};
  int tmp[4];
  std::cin >> num;
  for (int i=0; i<4; i++){
    tmp[i] = num/a[i];
    num-=tmp[i]*a[i];
  }
  if(tmp[0]*tmp[0]+tmp[1]*tmp[1]+tmp[2]*tmp[2] == 3*(tmp[0]*tmp[0]) || tmp[1]*tmp[1]+tmp[2]*tmp[2]+tmp[3]*tmp[3] == 3*(tmp[1]*tmp[1])){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }
  return 0;
}

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

typedef long long ll;
ll ans;

int main() {
	int n;
  	cin >> n;
  	for (int i = 1; i <= n; i++)
      	if (i % 3 && i % 5)
			ans += i;
  	cout << ans << endl;
}

Measured memory_bytes: 3636
s = input()
len_s = len(s)
cnt = 0
enemy = []
me = []
INF = 1e10
for i, _s in enumerate(s):
    if _s == "p":
        cnt += 1
    enemy.append(cnt)
    me.append((i+1) // 2)
    diff = (i + 1) // 2 - cnt
print(diff)

Measured memory_bytes: 51952
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;
using P = pair< int , int >;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

int main() {
	int n;
	cin >> n;
	map< P, int > ps;
	int x[n], y[n];

	rep(i , n) {
		cin >> x[i] >> y[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int dx = x[i] - x[j];
			int dy = y[i] - y[j];

			if (dx == 0) {
				if (dy < 0) {
					dy *= -1;
				}
			} else if (dx < 0) {
				dx *= -1;
				dy *= -1;
			}
			ps[mp(dx,dy)] ++;
		}
	}
	int max_v = 0;
	for ( auto p : ps) {
		max_v = max(p.second, max_v);
	}


	cout << n - max_v << endl;	
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    float ave = accumulate(a, a+n, 0) / (float)n;
    int ans = n;
    float min_diff = 1001001001;
    rep(i,n) {
        if (abs(a[n-i-1] - ave) <= min_diff) {
            min_diff = abs(a[n-i-1] - ave);
            ans = n-i-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
s = input()
t = input()
count = 0
num_s = len(s)
num_t = len(t)

for i in range(num_t):
    for j in range(i, num_s):
        if t[count] == s[j]:
            count += 1
        else:
            count = 0
            break

    if count == num_t - i:
        break
print(num_s+num_t-count)
    


Measured memory_bytes: 8952
#include<iostream>
#include<set>
using namespace std;struct P{int x,y,z;};bool operator<(P a,P b){return a.x!=b.x?a.x<b.x:(a.y!=b.y?a.y<b.y:a.z<b.z);}main(){for(int n,h,a,b,i;cin>>n>>h,n;){set<P>x;for(string c;h-->0;i=0)for(cin>>c>>a>>b;i++<n;){P p={a,i,b};if(c=="xy"){p.y=b;p.z=i;}if(c=="yz"){p.x=i;p.y=a;}x.insert(p);}cout<<n*n*n-x.size()<<endl;}}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    int yui = 0, kyoko = 0, aless = 0, bless = 0;
    vector<int> aa(n);
    for (int i = 0; i < n; i++) {
        cin >> aa[i];
    }
    vector<int> bb(n);
    for (int i = 0; i < n; i++) {
        cin >> bb[i];
    }
    
    rep(i, n) {
        int a = aa[i], b = bb[i];
        yui += a;
        kyoko += b;
        if (a < b) {
            aless += (b - a) / 2 + (b - a) % 2;
            bless += (b - a) % 2;
        } else if (b < a) {
            bless += a - b;
        }
    }
    int less = kyoko - yui;
    aless = less - aless;
    bless = less - bless;
    //cout << less << endl;
    if (less < 0) {
        cout << "No" << endl;
    } else if (less == 0) {
        if (!aless && !bless) {
            cout << "Yes" << endl;
        } else {
            std::cout << "No" << std::endl;
        }
    } else {
        //cout << aless << " " << bless << endl;
        if (aless < 0 || bless < 0) {
            std::cout << "No" << std::endl;
        } else if (aless * 2 == bless) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
    }

    return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  int N;
  int K;
  vector<long> H;
  
  cin >> N >> K;
  
  string buf;
  while (getline(cin, buf, ' ')) {
    H.push_back(stoi(buf));
  }
  
  sort(H.begin(), H.end(), [](int a, int b) { return a > b; });
  long num_attack = 0;
  for (int i = K; i < H.size(); ++i) {
    num_attack += H[i];
  }
  
  cout << num_attack << endl;
  
  return 0;
}

Measured memory_bytes: 2420
import math

A, B, X = map(int, input().split())
water = X / A # 水の面積
bottle = A * B # 水筒の面積
answer = 0
limit = A * B // 2
pour = bottle - water

if pour <= limit:
    answer = 90-math.degrees(math.atan2(A, pour * 2 / A))
else:
    answer = math.degrees(math.atan2(B, water * 2 / B))
print(answer)

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

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; }

using ll = long long;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll pow(ll a, ll n) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a) {
		if (n % 2LL == 1LL) {
			ret = ret * a;
		}
	}
	return ret;
}

ll f(ll n, ll x){
  if(x>=pow(2LL,n+2LL)-3) return pow(2LL,n+1LL)-1;
  if(x<=0LL) return 0LL;
  if(n==0LL&&x==1LL) return 1LL;
  if(x<=pow(2LL,n+1LL)-2LL) return f(n-1,x-1);
  if(x>pow(2LL,n+1LL)-2LL) return f(n-1,x-1)+1+f(n-1,x-pow(2LL,n+1LL)+1);
}

int main() {
  ll N, X;
  cin >> N >> X;
  cout<<f(N,X)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 212345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;

int32_t main() {
    $
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
}   



Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	int max = -1000000;
	int min = 1000000;
	long sum = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;

		sum += a;
		if (a > max)
		{
			max = a;
		}
		if (a < min)
		{
			min = a;
		}
	}

	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3108
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int res = 0;
    char s[105]; scanf("%s", s);
    for(int i=0; s[i]; i++) res ^= 1 << (s[i]-'a');
    puts(res == 0 ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int gcd(int a,int b,int c){
    int minj=0;
    for(int i=1;i<=min({a,b,c});i++){
        if(a%i==0 && b%i==0 && c%i==0){
            minj=i;
        }
    }
    return minj;
}

int main(){
   int k; cin>>k;
   int ans=0;
   for(int a=1;a<=k;a++){
       for(int b=1;b<=k;b++){
           for(int c=1;c<=k;c++){
               ans+=gcd(a,b,c);
           }
       }
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3640
# D - Fennec VS. Snuke
# https://atcoder.jp/contests/abc067/submissions/7707307
# https://atcoder.jp/contests/abc067/submissions/10252214
from collections import deque
n=int(input())
G=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

dist_f=[-1]*n
dist_s=[-1]*n
dist_f[0]=0
dist_s[n-1]=0

q = deque()
q.append(0)
while q:
    x = q.popleft()
    for nx in G[x]:
        if dist_f[nx] == -1:
            q.append(nx)
            dist_f[nx]=dist_f[x]+1
 
q = deque()
q.append(n-1)
while q:
    x = q.popleft()
    for nx in G[x]:
        if dist_s[nx] == -1:
            q.append(nx)
            dist_s[nx]=dist_s[x]+1
f,s=0,0
for i in range(n):
    if dist_f[i]<=dist_s[i]:
        f+=1
    else:
        s+=1
if f>s:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 29336
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	if(s=="abc"){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 768
num5 = 0
num7 = 0
for num in map(int, input().split()):
    if num == 5:
        num5 += 1
    elif num == 7:
        num7 += 1
    else:
        print('NO')
        exit()

if num5 == 2 and num7 == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <stdio.h>
#define SIZE 100011

int main(void) {
  int num, tmp, cnt = 0;
  scanf("%d", &num);
  int su[num];
  for (int i = 0; i < num; i++) {
    scanf("%d", &su[i]);
  }
  for (int i = 0; i < num; i++) {
    if (su[i] == i + 1 && i != num - 1) {
      tmp = su[i];
      su[i] = su[i + 1];
      su[i + 1] = tmp;
      cnt++;
    } else if (su[i] == i + 1) {
      tmp = su[i];
      su[i] = su[i - 1];
      su[i - 1] = tmp;
      cnt++;
    }
  }
  printf("%d", cnt);

  return 0;
}


Measured memory_bytes: 512
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] x=new int[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    }
    long min=Long.MAX_VALUE;
    for(int i=0;i+k-1<n;i++){
      min=Long.min(calc(x[i],x[i+k-1]),min);
    }
    System.out.println(min);
  }
  static long calc(long l,long r){
    if(l*r<0){
      return Long.min(
        Math.abs(l+l)+Math.abs(r),
        Math.abs(r+r)+Math.abs(l)
      );
    }else{
      return Long.max(Math.abs(l),Math.abs(r));
    }
  }
}

Measured memory_bytes: 48452
#include<stdio.h>
int main(void){
    while(1){
        int N,M;
        scanf("%d%d",&N,&M);
        int array[100]={0};
        if(N+M==0) break;
        for(int i=0;i<N;i++){
            int d,v;
            scanf("%d%d",&d,&v);
            if(array[d]<v){
                array[d]=v;
            }
        }
        int sum=0;
        for(int i=0;i<100;i++){
            sum+=array[i];
        }
        printf("%d\n",sum);
    }
}



Measured memory_bytes: 2040
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    map<ll,ll> m;
    ll sum = 0;
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
        sum+=a[i];
    }

    int q;
    cin>>q;
    rep(i,q){
        ll b,c;
        cin>>b>>c;

        ll s = m[b];
        sum-=b*s;
        sum+=c*s;
        cout<<sum<<endl;

        m[b]=0;
        m[c]+=s;

    }





return 0;
}


Measured memory_bytes: 10056
// #pragma GCC optimize(3)
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 100010
// #define int long long
using namespace std;
void write(int x){if(x<0){putchar('-');x=-x;}if(x>9) write(x/10);putchar(x%10+'0');}
int read(){int d=0,w=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')
w=-1;for(;c>='0'&&c<='9';c=getchar())d=(d<<1)+(d<<3)+c-48;return d*w;}
void wln(int x){write(x);putchar('\n');}
void wrs(int x){write(x);putchar(' ');}
int a[maxn],n,m,cnt;
bool cmp(int a,int b)
{
	return b<a;
}
signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;a[i++]=read());
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<n+2;i++)
		if(a[i]<i)
		{
			m=i-1;
			break;
		}
	// if(a[m+1]!=m&&a[m]==m) puts("Second");
	// if(a[m+1]==m&&a[m]==m)
	// {
	// 	for(int i=m;a[i+1]==m;i++)
	// 		cnt++;
	// 	puts(cnt&1?"First":"Second");
	// }
	// if(a[m]!=m&&a[m+1]!=m) puts(a[m]-m&1?"First":"Second");
	// if(a[m]!=m&&a[m+1]==m)
	// {
	for(int i=m;a[i+1]==m;i++)
		cnt++;
	puts(cnt&1||a[m]-m&1?"First":"Second");
	// }
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

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

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

public class Remainder
{
    
    static public void Main ()
    {
        var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = HW[0];
        var A = HW[1];
        var B = HW[2];
        
       
        
        if(N*A <= B){
            Console.WriteLine(N*A);
        }else{
            Console.WriteLine(B);
        }
        
    }
    
    
}

public class Node{
    public List<long> child;
    public long fnum = long.MaxValue;
    public long snum = long.MaxValue;
    public Node(){
        this.child = new List<long>();
    } 
}


Measured memory_bytes: 13268