akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var Q = cin.ReadInt;
            var S = cin.ReadLine.ToCharArray();

            int[] l = new int[Q];
            int[] r = new int[Q];

            for (int i = 0; i < Q; i++)
            {
                l[i] = cin.ReadInt;
                r[i] = cin.ReadInt;
            }

            int[] t = new int[N + 1];
            t[0] = 0;
            for (int i = 1; i < N; i++)
            {
                int ac = 0;
                if (S[i - 1] == 'A' && S[i] == 'C')
                {
                    ac = 1;
                }
                else{
                    ac = 0;
                }
                t[i] = t[i - 1] + ac;
            }

            for (int i = 0; i < Q; i++)
            {
                Console.WriteLine(t[r[i] - 1] - t[l[i] - 1]);
            }

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,0,h) cin>>s[i];

    rep(i,0,h){
        rep(j,0,w){
            if(s[i][j]=='#'){
                cout<<'#';
                continue;
            }else{
                int n=0;
                if(i>=1)
                Rep(k,-1,1){
                    if(j+k>=0&&j+k<w)
                    if(s[i-1][j+k]=='#') n++;
                }
                if(j-1>=0) if(s[i][j-1]=='#') n++;
                if(j+1<w) if(s[i][j+1]=='#') n++;
                if(i<h-1)
                Rep(k,-1,1){
                    if(j+k>=0&&j+k<w)
                    if(s[i+1][j+k]=='#') n++;
                }
                cout<<n;
            }
        }
        cout<<"\n";
    }
}

Measured memory_bytes: 256
typedef long long ll;

#define shi5 100000+10
#define MOD 1000000007

#include <bits/stdc++.h>
using namespace std;
struct mystruct{
  long long v;
  mystruct * next;
};
int structcmp(const void *v1,const void *v2){return ((mystruct *)v1)->v - ((mystruct *)v2)->v;}
int intcmp(const void *v1,const void *v2){return *(int *)v1-*(int *)v2;}
long long minn(long long v1,long long v2){return v1<v2?v1:v2;}
long long maxx(long long v1,long long v2){return v1>v2?v1:v2;}
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout<<(x-z)/(y+z)<<endl;
  return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll n; cin >> n;
    
    ll ans = 0;
    for (ll i = 1; i <= 100000; ++i) {
        if (i * i <= n) {
            ans = i * i;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
# **************************************************************************** #
#                                                                              #
#                                            __   __ .____  .__  __.  ____     #
#    F-bracketSequencing.py                 |  | |  ||  _ \ |  \/  | /    |    #
#                                           |  | |  || |_| || \  / ||  ,--'    #
#    By: ayahyao <y.anas1997@gmail.com>     |  | |  ||  __/ | |\/| ||  |       #
#                                           |  `-'  || |    | |  | ||  `--.    #
#    Created: 2020/05/10 18:38 by Anas       \_____/ |_|    |_|  |_| \____|    #
#    Updated: 2020/05/10 18:42 by Anas                                         #
#                                                                              #
# **************************************************************************** #

def     process(tab, beginning, end):
    total = beginning
    for i in tab:
        if (i[1] > total or total + i[0] < 0):
            return ("No")
        total += i[0]
    if (total == end):
        return ("Yes")
    return ("No")

def     parsing(N):
    beginning, ending = 0,0
    clean = 0
    total = 0
    tab = []

    for i in range(N):
        s = input()
        before, after = 0, 0
        for j in s:
            if (j == '('):
                after += 1
            elif (j == ')'):
                if (after > 0):
                    after -= 1
                else:
                    before += 1
        if (before == 0 and after > 0):
            beginning += after
        elif (after == 0 and before > 0):
            ending += before
        elif (before > 0 or after > 0):
            tab.append((after - before, before, after))
        else:
            clean += 1
        total += before - after
    tab = sorted(tab)[::-1]
    return tab, total, beginning, ending, clean


N  = int(input())
tab, total, beginning, ending, clean = parsing(N)
if (total == 0 and N == 1):
    res = "Yes"
elif ((total != 0) or ((min(beginning, ending) == 0 and clean == 0) 
                 or (max(beginning, ending) == 0 and clean == 1))):
    res = "No"
else:
    res = process(tab, beginning, ending)
print(res)


Measured memory_bytes: 26600
#include <stdio.h>
#include <algorithm>
using namespace std;
struct data{
    int s,e;
    bool operator<(const data&r)const{
        if(s==r.s)return e<r.e;
        return s<r.s;
    }
}a[300010];
struct Node{
    int cnt;
    Node *l,*r;
    Node(int cnt,Node *l,Node *r):cnt(cnt),l(l),r(r){}
    Node *update(int s,int e,int k);
}*root[300010];
Node *null=new Node(0,NULL,NULL);
Node *Node::update(int s,int e,int k){
    if(e<k||k<s)return this;
    if(s==e)return new Node(this->cnt+1,null,null);
    int m=(s+e)/2;
    return new Node(this->cnt+1,this->l->update(s,m,k),this->r->update(m+1,e,k));
}
int query(Node *a,int s,int e,int si,int ei){
    if(ei<s||e<si)return 0;
    if(si<=s&&e<=ei)return a->cnt;
    int m=(s+e)/2;
    return query(a->l,s,m,si,ei)+query(a->r,m+1,e,si,ei);
}
int main(){
    int i,j,k,l,n,m;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;++i)scanf("%d%d",&a[i].s,&a[i].e);
    sort(a+1,a+n+1);
    root[0]=null->l=null->r=null;
    for(i=1;i<=n;++i)root[i]=root[i-1]->update(1,m,a[i].e);
    for(i=1;i<=m;++i){
        j=i,k=0;
        int ans=0;
        for(;j<=m;j+=i){
            data t={j,m+1};
            l=upper_bound(a+k+1,a+n+1,t)-a-1;
            ans+=query(root[l],1,m,j,m)-query(root[k],1,m,j,m);
            k=l;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 171520
r,c=map(int,input().split())
s=[[]for R in range(r)]
t=[0 for C in range(c)]
for i in range(r):
    s[i]=list(map(int,input().split()))
    for j in range(c):
        print(s[i][j],end=' ')
        t[j]+=s[i][j]
    print(sum(s[i]))
for k in range(c):
    print(t[k],end=' ')
print(sum(t))


Measured memory_bytes: 5716
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  int n;
  F f;
  G g;
  T d1;
  E d0;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T d1,
	      vector<T> v=vector<T>()):
    f(f),g(g),d1(d1){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,E a){
    k+=n-1;
    dat[k]=g(dat[k],a);
    while(k>0){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
  inline T query(int a,int b){
    T vl=d1,vr=d1;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[(l++)-1]);
      if(r&1) vr=f(dat[(--r)-1],vr);
    }
    return f(vl,vr);
  }
  
};
ll gcd (ll a,ll b){
    return b ? gcd(b,a%b) : a;
}
//END CUT HERE
signed main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
  SegmentTree<ll,ll> rmq(N,
			   [](ll a,ll b){return gcd(a,b);},
			   [](ll a,ll b){return b;},
			   0);
    rep(i,0,N){
        rmq.update(i,V[i]);
    }
    ll ans = 0;
    rep(i,0,N){
        ll left = rmq.query(0,max(0,i));
        ll right = rmq.query(min(i+1,N),N);
        //cout << gcd(left, right) << endl;
        ans = max(ans, gcd(left, right));
    }
    if(N==2)ans = max(V[0], V[1]);
    cout << ans << endl;
}

Measured memory_bytes: 2688
import math

N = int(input())
h = list(map(int, input().split()))
dp = [float('INF')] * N

def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

#初期値
dp[0] = 0

#Loop
for i in range(1, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,t,u,v,l;
	int flg[10005]={0};
	cin>>n>>k>>t>>u>>v>>l;
	for(int i=0,j;i<n;i++){
		cin>>j;
		flg[j]=1;
	}
	int pos=0;
	int rem=0;
	int hav=0;
	double ans=0;
	while(pos<l){
		if(flg[pos]){
			if(hav==k)rem=t*v;
			else{
				hav++;
				if(rem==0){
					rem=t*v;
					hav--;
				}
			}
			ans+=1.0/v;
			rem--;
			if(rem==0 && hav>0){
				rem=t*v;
				hav--;
			}
		}
		else{
			if(rem>0){
				ans+=1.0/v;
				rem--;
				if(rem==0 && hav>0){
					rem=t*v;
					hav--;
				}
			}
			else{
				ans+=1.0/u;
			}
		}
		pos++;
	}
	printf("%.7f\n",ans);
	
	
	return 0;
}


Measured memory_bytes: 1236
import sys
from collections import deque

sys.setrecursionlimit(10 ** 5)


def solve(n, m, links):
    if m % 2 == 1:
        print(-1)
        return

    tree = [set() for _ in range(n)]
    parents = [-1] * n
    q = deque([0])
    while q:
        v = q.popleft()
        for u in links[v]:
            if parents[u] == -1:
                tree[v].add(u)
                parents[u] = v
                q.append(u)
            links[u].remove(v)

    parities = [len(l) % 2 for l in links]

    # print(links)
    # print(tree)
    # print(parents)
    # print(parities)

    def dfs(v):
        b = parities[v]
        for u in tree[v]:
            c = dfs(u)
            b ^= c
        if b:
            p = parents[v]
            links[p].remove(v)
            links[v].add(p)
        return b

    dfs(0)

    ans = ['{} {}'.format(v + 1, u + 1) for v in range(n) for u in links[v]]
    print('\n'.join(ans))


n, m = list(map(int, input().split()))

links = [set() for _ in range(n)]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)

solve(n, m, links)


Measured memory_bytes: 115220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll MOD=1e9+7;
const ll INF=1ll<<60;

//
//　定数, 変数 *********************************************
int N,M,X;

// *********************************************************
int main(){

    // N冊の参考書とM種類のスキル、両方とも12以下。
    // 各スキルはX以上にする
    cin >> N >> M >> X;
    
    int C[N];
    int A[N][M];
    for(int i=0; i<N; i++){
        cin >> C[i];
        for(int j=0; j<M; j++){
            cin >> A[i][j];
        }
    }

    int rikai[M];
    int sum;
    int hiyou = 1300000;  // max N*ciよりも高い

    // N M それぞれ最大12だから144全通りやってしまえばよいのだが、やり方がわからない
    // 他の人の手本を見た、ビット演算をすればよい。

    for(int i=1; i< pow(2,N); i++){
        //本の選び方は2^N通りある、その全てに対して可能性を試していく
        //Nは最大12なので、高々4096通りである。
        
        //initialize
        for(int i=0;i<M;i++){
            rikai[i]=0;
        }

        sum = 0;

        //ここが肝、これが知識不足でできなかった箇所
        for(int j=0; j<N; j++){
            if(i & (1 << j)){ //シフトしながらビット演算
                sum += C[j];  //j冊目を対象として選択する
                for(int k=0; k<M; k++){
                    rikai[k] += A[j][k];
                }
            }
        }

        //各スキルが要求を上回ったか？
        bool flag = true;
        for (int k = 0; k < M; k++)
        {
            if (rikai[k] < X) {
                flag = false;
                break;
            }
        }
        // 最小の値段か
        if (flag == true && hiyou > sum){
            hiyou = sum;
        }

        
    }

    if (hiyou == 1300000){
        cout << "-1" << endl;
    }else{
        cout << hiyou << endl;
    }
    
    return 0;

}

Measured memory_bytes: 4068
#include <iostream>
#include <string>
#include <set>
#include <vector>
using namespace std;

int main(){
  int n,h;
  while(true){
    cin >>n >>h;
    if (!n&&!h)
      break;
    int a,b;
    string c;
    set<int> xy;
    vector<set<int> >xz(n);
    vector<set<int> >yz(n);
    set<int>::iterator it;
    int block = 0;
    for(int i=0;i<h;i++){
      cin >>c >>a >>b;
      a--;
      b--;
      if (c == "xy")
	xy.insert(a*n+b);
      if (c == "xz")
	xz[b].insert(a);
      if (c == "yz")
	yz[b].insert(a);
    }
    for(int z=0;z<n;z++){
      block += (n-xz[z].size())*(n-yz[z].size());
      it = xy.begin();
      while( it != xy.end()){
	if (xz[z].find(*it/n)==xz[z].end()&&yz[z].find(*it%n)==yz[z].end())
	  block--;
	it++;
      }
    }
    cout << block << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<double> X(N), Y(N);
    rep(i, 0, N) {
        cin >> X[i] >> Y[i];
    }
    vector<int> idx(N);
    rep(i, 0, N) {
        idx[i] = i;
    }
    double sum = 0;
    do {
        double prev_x = X[idx[0]];
        double prev_y = Y[idx[0]];
        rep(i, 1, N) {
            sum += sqrt(pow(prev_x - X[idx[i]], 2) + pow(prev_y - Y[idx[i]], 2));
            prev_x = X[idx[i]];
            prev_y = Y[idx[i]];
        }
    } while (next_permutation(all(idx)));
    rep(i, 1, N + 1) {
        sum /= i;
    }
    cout << fixed << setprecision(10) << sum << endl;
    return 0;
}

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

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


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

	int a[110];
	for (int i = 0; i < T; i++)
		cin >> a[i];

	sort(a, a + T);
	reverse(a,a + T);

	cout << max(a[0] - 1-(K - a[0]), 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 int a,b,c;
 cin >> a >> b >> c;
 bool d=false;
 if(b-a==c-b || a-b==b-c)d=true;
 if(d)cout << "YES" << endl;
 else cout << "NO" << endl;
}

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

int main() {
  int a,b,c,x,sum=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(x==i*500+j*100+k*50)
          sum++;
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int n,m;
    cin>>n>>m;
    Vi L(m),R(m);
    REP(i,m){
        cin>>L[i]>>R[i];
        L[i]--;
    }

    Vi cards(n+5,0);
    REP(i,m){
        cards[L[i]]++;
        if(R[i]>n) cards[n+1]--;
        else cards[R[i]]--;
    }

    REP2(i,1,n+1){
        cards[i] += cards[i-1];
    }

    LL cnt = 0;
    REP(i,n){
        if(cards[i]==m) cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}

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

struct Edge {
  Edge() {}
  Edge(int from, int to, int capacity, int rev) : from(from), to(to), capacity(capacity), rev(rev) {}
  int from, to;
  int capacity;
  int rev;
};

std::vector<Edge> edges[1024];
void addEdge(int from, int to, int capacity) {
  int n1 = edges[from].size();
  int n2 = edges[to].size();
  edges[from].push_back(Edge(from, to, capacity, n2));
  edges[to].push_back(Edge(to, from, 0, n1));
}

bool checked[1024];
void init_flow() {
  for(int i = 0; i < 1024; ++i) {
    checked[i] = false;
  }
}
int flow(int from, int to, int v) {
  if( from == to ) return v;
  if( v == 0 ) return 0;
  if( checked[from] ) return 0;
  checked[from] = true;
  for(Edge& edge : edges[from]) {
    int nv = std::min(v, edge.capacity);
    int f = flow(edge.to, to, nv);
    if( f == 0 ) continue;
    edge.capacity -= f;
    edges[edge.to][edge.rev].capacity += f;
    return f;
  }
  return 0;
}

int maximum_flow(int from, int to) {
  int res = 0;
  for(;;) {
    init_flow();
    int f = flow(from, to, (1 << 29));
    res += f;
    if( f == 0 ) break;
  }
  return res;
}

int source = 1022;
int dest   = 1023;

int m, n;
int xs[1024];
int ys[1024];
bool load() {
  scanf("%d %d", &m, &n);
  if( m == 0 and n == 0 ) return false;
  for(int i = 0; i < m; ++i) {
    scanf("%d", &xs[i]);
  }
  for(int i = 0; i < n; ++i) {
    scanf("%d", &ys[i]);
  }
  return true;
}

int gcd(int x, int y) {
  while( y != 0 ) {
    x %= y;
    std::swap(x, y);
  }
  return x;
}

int solve() {
  for(int i = 0; i < 1024; ++i) {
    edges[i].clear();
  }
  for(int i = 0; i < m; ++i) {
    for(int j = 0; j < n; ++j) {
      if( gcd(xs[i], ys[j]) != 1 ) {
        addEdge(i, 512 + j, 1);
      }
    }
  }
  for(int i = 0; i < m; ++i) {
    addEdge(source, i, 1);
  }
  for(int i = 0; i < n; ++i) {
    addEdge(512 + i, dest, 1);
  }
  return maximum_flow(source, dest);
}

int main() {
  while( load() ) {
    printf("%d\n", solve());
  }

  return 0;
}

Measured memory_bytes: 11508
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin>>S;
  int cnt=0;
  for(int i=1;i<S.size();i++){
    if(S.at(i-1)!=S.at(i))cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

#define int long long
const int mod=1000000007;
int N,R;
int w[100000];

int bit_n,bit[101010];
void init(int n){bit_n=n;memset(bit,0,sizeof(bit));}
void add(int k,int x){for(k++;k<=bit_n;k+=k&-k)bit[k]+=x;}
int sum(int k){int ret=0;for(k++;k;k-=k&-k)ret+=bit[k];return ret;}


int fact[101010];

signed main(){
    fact[0]=1;
    for(int i=1;i<101010;i++)fact[i]=fact[i-1]*i%mod;

    cin.tie(0);
    ios_base::sync_with_stdio(0);

    while(cin>>N,N){
        cin>>R;
        rep(i,N)w[i]=i;
        while(R--){
            int a,b;
            cin>>a>>b;
            a--;b--;
            swap(w[a],w[b]);
        }

        init(N);
        int ans=0;
        rep(i,N){
            int cnt=w[i]-sum(w[i]);
            ans=(ans+cnt*fact[N-i-1])%mod;
            add(w[i],1);
        }
        cout<<ans<<endl;
    }
    return 0;

}

Measured memory_bytes: 3560
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)
#define MOD (ll)(1e9+7)
 
#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)
 
//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;

ll cnt[26];

void solve() {
    string s;
    cin >> s;
    ll n = s.size();
    ll ans = 1+(n*(n+1))/2;
    rep(i,0,n) {
        cnt[s[i]-'a']++;
    }
    rep(i,0,26) {
        ans -= (cnt[i]*(cnt[i]+1))/2;
    }
    cout << ans << endl;
}
 
int main() {
    solve();
}

Measured memory_bytes: 640
#include <stdio.h>
 
int calc(int x,int y){
    if(y == 0){
        return x;
    }else{
        return calc(y,x%y);
    }
}
 
int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    if(x >= y)
        printf("%d\n",calc(x,y));
    else{
        printf("%d\n",calc(y,x));
    }
}


Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  int sum = 0;
  rep(i, s.size()){
    sum += s[i] - '0';
  }

  cout << (sum % 9 == 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3752
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

N, K, C = map(int, input().split())
S = input()

left = [0] * N
right = [0] * N

i = 0
cnt = 0
while i < N:
    if cnt == K:
        break
    if S[i] == "o":
        cnt += 1
        left[i] = 1
        i += C + 1
    else:
        i += 1
#print(left)

S = S[::-1]
i = 0
cnt = 0
while i < N:
    if cnt == K:
        break
    if S[i] == "o":
        cnt += 1
        right[i] = 1
        i += C + 1
    else:
        i += 1
right = right[::-1]
#print(right)

left_ls, right_ls = [], []
for i in range(N):
    if left[i]:
        left_ls.append(i + 1)
    if right[i]:
        right_ls.append(i + 1)
        
for l, r in zip(left_ls, right_ls):
    if l == r:
        print(l)

Measured memory_bytes: 100972
n = int(input())
b = list(map(int, input().split()))

a = [0] * n
a[0] = b[0]

for i in range(1, n-1):
  a[i] = min(b[i-1], b[i])

a[-1] = max(a[-1], b[-1])

print(sum(a))

Measured memory_bytes: 3064
O, E = [input() for i in range(2)]
ans = ''
if len(O) > len(E):
    E += "Z"
    for i, j in zip(O, E):
            ans += i
            ans += j
    print(ans[0:-1])
else:
    for i, j in zip(O, E):
            ans += i
            ans += j
    print(ans)

Measured memory_bytes: 3060
import Data.List ( transpose )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  c1 <- readInts
  c2 <- readInts
  c3 <- readInts
  putStrLn $ if f c1 c2 c3 
               then "Yes"
               else "No"

f :: [Int] -> [Int] -> [Int] -> Bool
f c1 c2 c3 = let c = [c1,c2,c3] in
  yoko c && tate c

yoko, tate 
  :: [[Int]] -> Bool
yoko [c1@[c11,c12,c13], c2@[c21,c22,c23], c3@[c31,c32,c33]]
  = all (==c11-c21) (zipWith (-) c1 c2) &&
    all (==c21-c31) (zipWith (-) c2 c3) &&
    all (==c31-c11) (zipWith (-) c3 c1) 

tate = yoko . transpose

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

signed main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    REP(i,n){
        cin >> p[i];
    }
    REP(i,n){
        cin >> q[i];
    }
    vector<int> v(n);
    REP(i,n){
        v[i] = i + 1;
    }
    int cnt = 1;
    int a, b;
    do{
        if(p == v) a = cnt;
        if(q == v) b = cnt;
        cnt++;
    }while(next_permutation(ALL(v)));
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    int n;
    R n;
    set<string> st;
    char pre;
    rep(i, n){
        string w;
        R w;
        if(i&&w[0]!=pre){
            co("No");
            return 0;
        }
        pre=w[w.size()-1];
        st.in(w);
    }
    if(st.size()!=n)co("No");
    else co("Yes");
}

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

int main( ) {
  string s(3,'0');
  cin >> s;
  
  for(int i = 0; i < 3; i++) {
    if(s[i] == '1'){
      s[i] = '9';
    } else if(s[i] == '9'){
      s[i] = '1';
    }
  }
  
  cout << s;
}

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

int main() {
  int N;
  cin >> N;
  vector<char> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  int ans = true;
  for (int i = 0; i < N; i++) {
    ans = !(ans && P[i] == 'F');
  }
  cout << ( (ans) ? 'T' : 'F' ) << endl;
}



Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main (){
    long long n;
    cin >>n;
    long long X;
    X=sqrt(n);
    long long min =100000000000000;
    for( long long i=1;i<=X;i++){
        if(n/i+i<min&&n%i==0){
            min =n/i+i;
        }
    }
    cout << min -2 << endl;
    return 0;
}

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

int main(){
  int n;
  cin >>n;
  long long A[n+1];
  long long B[n];
  for(int i=0;i<=n;i++){
    cin>>A[i];
  }
  for(int i=0;i<n;i++){
    cin>>B[i];
  }
  long long ans=0;
  for(int i=0;i<n;i++){
    if(B[i]>A[i]){
      ans+=A[i];
      ans+=min((B[i]-A[i]),A[i+1]);
      A[i+1]=A[i+1]+A[i]-B[i];
      if(A[i+1]<0){
        A[i+1]=0;
      }
    }
    else{
      ans+=B[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 5092
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_map>
typedef long long int ll;
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<" "<<x<<"\n";
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
    cr7
        ll n;
    cin >> n;
    set<string> S;
    for (ll i = 0; i < n; i++) {
        string s;
        cin >> s;
        S.insert(s);
       }
    cout << S.size() << "\n";
    return 0;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

map <ll, ll> mp ;

int main()
{
    ll n, val ;
    cin >> n ;
    for (int i = 1; i <= n; i++) {
        mp[i] = 0 ;
    }
    for (int i = 1; i <= 100; i++) {
        for (int j = 1; j <= 100; j++) {
            for (int k = 1; k <= 100; k++) {
                val = (i * i) + (j * j) + (k * k) + (i * j) + (j * k) + (k * i) ;
                mp[val]++ ;
            }
        }
    }
    for (auto it = mp.begin(); it != mp.end(); it++) {
        if (it->first > n)  break ;
        cout << it->second << endl ;
    }

    return 0 ;
}


Measured memory_bytes: 5988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int x;
cin>>x;
if (x<1200)
{
    cout<<"ABC"<<endl;
}
else
{
    cout<<"ARC"<<endl;
}

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  alist = list(map(int, input().split()))
  ans = [0 for _ in range(n+1)]
  anss = 0
  res = []
  for i in range(n, 1, -1):
    if ans[i]%2 != alist[i-1]:
      anss += 1
      res.append(i)
      j = 1
      while j*j <= i:
        if i % j == 0:
          if j*j == i:
            ans[j] += 1
          else:
            ans[j] += 1
            ans[i//j] += 1
        j += 1
    
  if ans[1] %2 != alist[0]:
    print(anss+1)
    res.append(1)
    res.reverse()
    print(*res)
  else:
    print(anss)
    if res:
      res.reverse()
      print(*res)


if __name__ == '__main__':
  main()


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

int main()
{
    int n, alice = 0, bob = 0;
    cin >> n;
    vector<int> card(n);

    for (int i = 0; i < n; i++)
    {
        cin >> card.at(i);
    }
    sort(card.begin(), card.end());
    reverse(card.begin(), card.end());
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            alice += card.at(i);
        }
        else
        {
            bob += card.at(i);
        }
    }
    cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

/* 繰り返しニ乗法(MOD計算込み)*/
int modPow(ll a, ll n) {
	// 一番下
	if (n == 1) return a % MOD;

	// nが奇数の時は偶数と2に分ける
	if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
	
	// nが偶数の時は1/2に分ける
	ll t = modPow(a, n / 2);
	return (t * t) % MOD;
}

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

	ll n, a, b;
	cin >> n >> a >> b;
	
	ans = modPow(2, n) - 1;

	ll nca_si = 1; // nCaの分子
	for (ll i = n - a + 1; i <= n; i++) {
		nca_si = (nca_si*i) % MOD;
	}

	ll ncb_si = 1; // nCbの分子
	for (ll i = n - b + 1; i <= n; i++) {
		ncb_si = (ncb_si*i) % MOD;
	}

	ll nca_bo = 1; // nCaの分母
	for (ll i = 1; i <= a; i++) {
		nca_bo = (nca_bo*i) % MOD;
	}

	ll ncb_bo = 1; // nCbの分母
	for (ll i = 1; i <= b; i++) {
		ncb_bo = (ncb_bo*i) % MOD;
	}

	ll nca_bo_inverse = modPow(nca_bo, MOD - 2);
	ll ncb_bo_inverse = modPow(ncb_bo, MOD - 2);

	ll nca = (nca_si * nca_bo_inverse) % MOD;
	ll ncb = (ncb_si * ncb_bo_inverse) % MOD;

	ans = (ans - nca - ncb + 2 * MOD) % MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <limits>

//n, m = list(map(int, input().split()))
//key = []
//for _ in range(m):
//a, b = list(map(int, input().split()))
//c = list(map(int, input().split()))
//key.append((a,c))
class Key{
public:
    Key(int open_box, int cost){
        open_box_ = open_box;
        cost_ = cost;
    }
    int open_box_;
    int cost_;
};

//int dp[2][2][2][2][2][2][2][2][2][2][2][2][1000+1];
int dp[4096][1000+1];
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    Fill(dp, std::numeric_limits<int>::max());
//    std::string binary = std::bitset<12>(4095).to_string(); //to binary
//    std::cout<<binary<<"\n";
//
//    int decimal = int(std::bitset<12>(binary).to_ullong());
//    std::cout<<decimal<<"\n";


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

    int n, m;
    std::cin >> n >> m;
    std::vector<Key> keys;
    for (int i = 0; i < m; ++i) {
        int cost, b;
        std::cin >> cost >> b;
        std::string binary_open = std::bitset<12>(0).to_string();
        for (int j = 0; j < b; ++j) {
            int tmp;
            std::cin >> tmp;
            binary_open[11 - (tmp-1)] = '1';
        }
        keys.push_back(Key(int(std::bitset<12>(binary_open).to_ullong()), cost));
    }

    for (int i = 1; i < m+1; ++i) {
        auto key = keys[i-1];
        for(int j=0; j<4096; j++){
            if(j==key.open_box_){
                if(dp[j][i-1] > key.cost_)
                    dp[j][i] = key.cost_;
                else
                    dp[j][i] = dp[j][i-1];
            }

            if(dp[j][i-1] != std::numeric_limits<int>::max()){
                // tmp value
                if(dp[j][i] == std::numeric_limits<int>::max())
                    dp[j][i] = dp[j][i-1];

                // calculate cost
                int tmp_cost = key.cost_ + dp[j][i-1];
                if(tmp_cost < dp[j|key.open_box_][i-1]){
                    if(tmp_cost < dp[j|key.open_box_][i])
                        dp[j|key.open_box_][i] = tmp_cost;
                }
            }
        }
    }

    std::string binary_open = std::bitset<12>(0).to_string();
    for (int j = 0; j < n; ++j) {
        binary_open[11 -j] = '1';
    }

    int final = dp[int(std::bitset<12>(binary_open).to_ullong())][m];
    if(final==std::numeric_limits<int>::max()){
        std::cout << "-1" << std::endl;
    }else{
        std::cout << final <<std::endl;
    }
//    for (int i=0;i<n;i++){
//        std::cout << a[i] << std::endl;
//    }

    return 0;
}

Measured memory_bytes: 16256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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 T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n, b - 1);
    cout << a * x / b - a * (x / b) << endl;
}

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

int main()
{
    vector<int> x(4), y(4);
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    int difx = x[1] - x[0];
    int dify = y[1] - y[0];

    cout << x[1] - dify << " " << y[1] + difx << " " << x[0] - dify << " " << y[0] + difx << endl; 
}

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

int main(){
  int N;
  cin >> N;
  int loop=(int)sqrt((double)N);
  while((loop*(loop+1))/2<N){
    loop++;
  }
  int over=((loop*(loop+1))/2)-N;
  int max = loop;
  for(loop=1;loop<=max;loop++){
    if(loop==over){
      continue;
    }
    cout << loop << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n, m;
    cin >> n >> m;

    cout << (n*(n-1)/2) + (m*(m-1)/2) << "\n";
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

int main(void){
    long N;
    scanf("%ld",&N);

    int ans=11;
    for(long i=1;i*i<=N;i++){
        if(N%i==0){
            int tmp = log10(N/i)+1;
            ans=MIN(ans,tmp);
        }
    }
    printf("%d\n",ans);

    return 0;
}

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

int main()
{
  int k, ans, deka, goke;
  vector<int> a(3);
  int i;
  goke = 0;
  for(i=0; i<3; i++)
  {
    cin >> a[i];
    goke += a[i];
  }
  cin >> k;
  deka = 0;
  for(i=0; i<3; i++)
  {
    if(deka < a[i])deka = a[i];
  }
  goke -= deka;
  for(i=0; i<k; i++)
  {
    deka *= 2;
  }
  ans = deka+goke;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
r,g,b,n = map(int, input().split())
# 大きい順にやっていけばいけるけど...?

m1,m2,m3 = sorted([r,g,b])
count = 0
for k in range((n // m3)+1):
  now_n = n-k*m3
  for u in range((now_n // m2)+1):
    if (now_n - m2*u) % m1 == 0:
      count += 1
print(count)

Measured memory_bytes: 20484
a, b, c = map(int, input().split(' '))

count = 0

while(1):
    # print(a,b,c)
    if a == b == c:
        break
    if a == b and b < c:
        a += 1
        b += 1
        count += 1
    elif b == c and c < a:
        b += 1
        c += 1
        count += 1
    elif c == a and a < b:
        c += 1
        a += 1
        count += 1
    else:
        if a == min(a,b,c):
            a += 2
            count += 1
        elif b == min(a,b,c):
            b += 2
            count += 1
        elif c == min(a,b,c):
            c += 2
            count += 1
print(count)

Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input! {
        mut a: isize,
        b: isize,
        mut c: isize,
        d: isize,
    }

    while a > 0 && c > 0 {
        c -= b;
        if c <= 0 {
            println!("Yes");
            return;
        }

        a -= d;
        if a <= 0 {
            println!("No");
            return;
        }
    }
}


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

int main() {
	char  c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
		cout << "vowel";
	}
	else {
		cout << "consonant";
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int X;

vector<int> factor(int n) {
  vector<int> x;
  for (int i = 2; i <= n; i++) {
    while (n%i == 0) {
      x.push_back(i);
      n /= i;
    }
  }
  return x;
}

int pow(int a, int b) {
  int ans = 1;
  while (b--) { ans *= a; }
  return ans;
}

void solve() {
  vector<int> f = factor(X);
  int bit = 0;

  for (long long a = -178; a <= 178; a++) {
    for (long long b = -178; b <= 178; b++) {
      if (a*a*a*a*a - b*b*b*b*b == X) {
        cout << a << " " << b << endl;
        return;
      }
    }
  }

}

int main() {
  cin >> X;
  solve();
  return 0;
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int r, d, x;
  cin >> r >> d >> x;
  vector<int> v(11);
  v[0] = x;
  REP(i, 10){
    v[i+1] = r * v[i] - d;
    cout << v[i+1] << endl;
  }
  return 0;
}

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

void drop(vector<string> &cp){
  for(int j=0;j<w;j++){
    int empcnt=0;
    for(int i=h-1;i>=0;i--){
      if(cp[i][j]=='.') empcnt++;
      else if(empcnt>0){
	cp[i+empcnt][j]=cp[i][j];
	cp[i][j]='.';
      }
    }
  }
  return;
}

bool clear(vector<string> &cp){
  bool cleared=false;
  vector<vector<int>> cl(h,vector<int>(w,0));
  for(int i=0;i<h;i++){
    int prec='&'-'A';
    int cnt=0;
    for(int j=0;j<w;j++){
      if(prec==(cp[i][j]-'A')){
	cnt++;
      }
      else{
	if(cnt>=n){
	  for(int k=j-cnt;k<j;k++){
	    cl[i][k]=true;

	  }
	}
	if(isalpha(cp[i][j])){
	  prec=(cp[i][j]-'A');
	  cnt=1;
	}
	else{
      	  cnt=-10000;
	  prec='&'-'A';
	}
      }
    }
    if(prec!='&'-'A' && cnt>=n){
      for(int k=w-cnt;k<w;k++){

	cl[i][k]=true;
      }
    }
  }

  for(int j=0;j<w;j++){
    int prec='&'-'A';
    int cnt=-10000;
    for(int i=0;i<h;i++){
      if(prec==(cp[i][j]-'A')){

	cnt++;
      }
      else{
	if(cnt>=n){
	  for(int k=i-cnt;k<i;k++){
	    cl[k][j]=true;

	  }
	}
	  if(isalpha(cp[i][j])){
	    cnt=1;
	    prec=(cp[i][j]-'A');
	  }
	  else{
	    cnt=-10000;
	    prec='&'-'A';
	  }
	  
      }
      
    }
    if(prec!='&'-'A' && cnt>=n){
      for(int k=h-cnt;k<h;k++){
	cl[k][j]=true;

      }
    }
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(cl[i][j]){
	cp[i][j]='.';
	cleared=true;
      }
    }
  }
  return cleared;
}


bool check(vector<string> &cp){
  bool no_block=true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      no_block=(no_block && cp[i][j]=='.');

    }

  }
  if(no_block) return true;
  drop(cp);
  if(!clear(cp)) return false;
  return check(cp);
}

int main(){
  cin>>h>>w>>n;
  vector<string> b(h);
  for(int i=0;i<h;i++) cin>>b[i];
  bool res=false;
  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      vector<string> cp=b;
      swap(cp[i][j],cp[i][j+1]);
      res=res||check(cp);
      if(res){
	j=w;
	i=h;
      }
    }
  }
  cout<<(res?"YES":"NO")<<endl;

  return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
     
int main() {
	vector<vector<int>> cards(4, vector<int>(13));
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13 ; j++){
			cards.at(i).at(j)=0;
		}
	}
	int n;
	cin >> n ;
	for(int h = 0; h < n; h++){
		int num;
		char mar;
		cin>> mar >> num;
		if(mar == 'S'){
			cards.at(0).at(num - 1) = 1;
		}
		if(mar == 'H'){
			cards.at(1).at(num - 1) = 1;
		}
		if(mar == 'C'){
			cards.at(2).at(num - 1) = 1;
		}
		if(mar == 'D'){
			cards.at(3).at(num - 1) = 1;
		}
	}
	for(int i = 0; i < 4 ; i++){
		for(int j = 0; j < 13; j++){
			if(cards.at(i).at(j) == 0){
				if(i == 0){
				cout<< "S " << j + 1 << endl;
				}
				if(i == 1){
				cout<< "H " << j + 1 << endl;
				}
				if(i == 2){
				    cout<< "C " << j + 1 << endl;
				}
				if(i == 3){
				    cout<< "D " << j + 1 << endl;
				}
			}
		}
	}
}



Measured memory_bytes: 3128
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

s = input()
t = input()

ans = inf
for i in range(len(s)-len(t)+1):
    tmp = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            tmp += 1
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 10228