akhauriyash/Code-Regression huggingface dataset:
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <list>
#include <deque>
#include <bitset>
#include <numeric>
#include <iomanip>

using namespace std;

inline int toInt(string s) {int d; istringstream iss(s); iss >> d; return d;}
template<class T> inline string toString(T d) {ostringstream oss; oss << d; return oss.str();}

template<class T> inline T pow2(T x) {return x*x;}

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> VI;
typedef vector<string> VS;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SORT(v) sort(ALL(v))
#define PB push_back
#define MP(x,y) make_pair(x,y)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define PARSE(type, v, str) {istringstream iss(str); type val; while(iss >> val) v.push_back(val);}

const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = 1000000000;
const ll LLINF = 10000000000000000LL;

#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

ll N, X;

ll gcd(ll a, ll b) {
  return (b==0)?a:gcd(b,a%b);
}

int main()
{
  ios::sync_with_stdio(false);

  cin >> N >> X;
  ll g = gcd(N,X);
  N /= g;
  ll ans = (N-1)*3 * g;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
suits=["S","H","C","D"]
cards=[]
for t in range(n):
    s,t=input().split()
    if s=="S":
        cards.append(int(t))  
    elif s=="H":
        cards.append(13+int(t))
    elif s=="C":
        cards.append(26+int(t))
    else:
        cards.append(39+int(t))

for u in range(1,53):
    if u not in cards:
        print(suits[(u-1)//13],(u-1)%13+1)


Measured memory_bytes: 5600
#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>;

const ll MAXV = 1e18;

int main()
{
    int n;
    ll ans = 1;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if ( a[i] > MAXV / ans )
        {
            ans = -1;
            break;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

int dx[]={1,1,0,-1,-1,-1,0,1}, dy[]={0,-1,-1,-1,0,1,1,1};
int cnt = 0;
int gg[60][60];
int w,h;
void solve(int x, int y){
    //cout<<x<<" "<<y<<"aaaaaa"<<endl;
    gg[x][y]=0;
    //if(x==2 && y == 48) cout<<"probrem"<<endl;
    rep(i,8){
        int nx = x + dx[i], ny = y + dy[i];
        /*if(x==2 && y==48){
            cout<<nx<<" "<<ny<<endl;
        }*/
        if(nx<h && nx>=0 && ny<w && ny>=0 && gg[nx][ny]==1){
            //cout<<nx<<" "<<ny<<endl;
            solve(nx,ny);
        }
    }
}

int main(){
    while(1){
        cin>>w>>h;
        rep(i,60) rep(j,60) gg[i][j]=0;
        cnt = 0;
        if(w==0 && h==0) break;
        rep(i,h) rep(j,w) cin>>gg[i][j];
        rep(i,h) rep(j,w){
            if(gg[i][j]==1) {
                //cout<<i<<" "<<j<<"start"<<endl;
                cnt++;
                solve(i,j);
                /*rep(i,h){
                    rep(j,w) cout<<gg[i][j]<<" ";
                    cout<<endl;
                }*/
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    set<int> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    if(st.size()==2) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
L = [0]*len(s)
for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] =="C":
        L[i+1] = 1
L = [0]+L
for i in range(1,len(s)+1):
    L[i]+=L[i-1]
#print(L)
for i in range(k):
    a,b = map(int,input().split())
    print(L[b]-L[a])

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

using namespace std;

int main(void) {

	int h, w;
	char a[100][100];

	cin >> h >> w;

	for (int i = 0; i < h; i++) {
			cin >> a[i];
	}

	for (int i = 0; i < h+2; i++) {
		for (int j = 0; j < w+2; j++) {
			if (i == 0 || i == h+1 || j == 0 || j == w+1) cout.put('#');
			else cout.put(a[i - 1][j - 1]);
		}
		cout << endl;
	}

	return 0;

}

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

int main() {
  string s;
  cin >> s;
  bool flag=false;
  for(int i=0;i<s.size()-1;i++) {
    if(s.at(i)==s.at(i+1)) {
      flag=true;
      break;
    }
  }
  if(flag) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n;

vi v;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
  }
}

int a[100001], b[100001];

void solve() {
  int nr1 = 0, x1, max2 = 0, second;
  for(int i = 0; i < n; i += 2) {
    ++a[v[i]];
    if (a[v[i]] > nr1) {
      if (x1 != v[i]) {
        max2 = nr1;
        second = x1;
      }
      nr1 = a[v[i]];
      x1 = v[i];
    } else if (a[v[i]] > max2) {
      max2 = a[v[i]];
      second = v[i];
    }
  }

  int nr2 = 0, x2, max3 = 0, secondd;
  for(int i = 1; i < n; i += 2) {
    ++b[v[i]];
    if (b[v[i]] > nr2) {
      if (x1 != v[i]) {
        max3 = nr2;
        secondd = x2;
      }
      nr2 = b[v[i]];
      x2 = v[i];
    } else if (b[v[i]] > max3) {
      max3 = b[v[i]];
      secondd = v[i];
    }
  }
  if (x2 == x1) {
    if (nr1 == nr2) {
      if (max2 > max3)
        nr1 = max2;
      else nr2 = max3;
    }
    else if (nr1 > nr2) {
      nr2 = max3;
    } else nr1 = max2;
  }
  cout << n - nr1 - nr2;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


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

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

  map<int, int> map;

  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;

    auto ite = map.find(num);
    if (ite != map.end()) {
      map[num] = map[num] +1;
    } else {
      map[num] = 1;
    }
  }

  int ans = 0;
  for(auto entry : map) {
    if (entry.second % 2 != 0) {
      ans++;
    }
  }

  std::cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll i,j,k,l,m,n,a,b,c,d,cnt=0;
    cin>>n;
    m=n%10;
    if(m==2 ||m==4 ||m==5 ||m==7|| m==9)
        cout<<"hon"<<endl;
    else if(m==0 || m==1 || m==6 || m==8)
        cout<<"pon"<<endl;
    else if(m==3)
        cout<<"bon"<<endl;

}


Measured memory_bytes: 3592
from math import sqrt


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_bills, total_value = tuple(input_ints())
    for i in range(0, num_bills + 1):
        for j in range(0, num_bills - i + 1):
            k = num_bills - i - j
            if i * 10000 + j * 5000 + k * 1000 == total_value:
                print(i, j, k)
                return

    print(-1, -1, -1)


main()


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

using namespace std;

int main() {
    int r = 0, cnt = 0;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        switch (s.at(i)) {
            case 'g': ++r; break;
            case 'p': if (r) {
                --r;
            } else {
                ++r;
                --cnt;
            } break;
        }
    }
    cout << cnt + r / 2 << endl;
    return 0;
}


Measured memory_bytes: 512
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, m = sc.nextInt()
    var ans = 0
    for (a <- 1 to math.sqrt(m).toInt) {
      if (m % a == 0) {
        val b = m / a
        if (a.toLong * n <= m) ans = math.max(ans, a)
        if (b.toLong * n <= m) ans = math.max(ans, b)
      }
    }
    println(ans)
  }
}

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

#define ll long long

void solve(){
    ll x, k, d; cin>>x>>k>>d;
    x = abs(x);
    ll i = ceil(x/d);
    i = (i>k ? k: i);
    x = (k-i)%2 == 0 ? x-i*d : x-(i+1)*d;
    cout<<abs(x)<<endl;
}

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


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;


#define INF 1e+9



int main(){

	  int n,m;
	  cin >> n >> m;
	  vector<int> c(m+1,0);
	  for(int i=1; i<=m; i++)
			cin >> c[i];

/*
	  // ???????????????
	  vvi dp(m+2,vi(n+1,INF));  
	  dp[0][0] = 0;
	  for(int i=0; i<=m; i++){
			for(int j=0; j<=n; j++){
				  dp[i+1][j] = min(dp[i][j], dp[i+1][j]); 
				  if(j+c[i] > n) continue;
				  dp[i][j+c[i]] = min(dp[i][j]+1,dp[i][j+c[i]]); 
				  dp[i+1][j+c[i]] = min(dp[i][j]+1,dp[i+1][j+c[i]]); 
			}
	  }
	  cout << dp[m][n] << endl;
*/
	  //??????????????????
	  vvi dp(m+1,vi(n+1,INF));  
	  dp[0][0] = 0;
	  for(int i=1; i<=m; i++){
			for(int j=0; j<=n; j++){
				  dp[i][j] = min( dp[i][j], dp[i-1][j]); 
				  if(j-c[i] < 0) continue;
				  dp[i][j] = min( dp[i][j], dp[i][j-c[i]] + 1 );
				  //dp[i][j] = min( dp[i][j], dp[i-1][j-c[i]] + 1); 
			}
	  }
	  cout << dp[m][n] << endl;
	  

	  // dp[i][j]: i???????????????????????§??§???j??????????????????????????????????°??????°

  

}

Measured memory_bytes: 5264
import sys

input = sys.stdin.readline


def main():
    A, B, C = map(int, input().split())
    K = int(input())

    max_v = max(A, B, C)

    ans = sum((A, B, C)) - max_v + max_v * 2 ** K
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

vector< vector<ll> > dp;
vector< vector<int> > g;

ll dfs(int cur, int cur_color, int par) {
	ll& res = dp[cur][cur_color];
	if (res >= 0) return res;
	
	res = 1;
	for (int nex : g[cur]) {
		if (nex == par) continue;
		ll tmp = dfs(nex, 0, cur);
		if (cur_color == 0) (tmp += dfs(nex, 1, cur)) %= MOD;
		(res *= tmp) %= MOD;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	g.resize(n);
	dp.assign(n, vector<ll>(2, -1));
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	ll ans = (dfs(0, 0, -1) + dfs(0, 1, -1)) % MOD;
	cout << ans << endl;
	return 0;
}

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

int main(){
	int N, K, i;
	scanf("%d%d", &N, &K);
	string S;
	cin >> S;
	int count = 0;
	for(i = 1; i < N; i++){
		if(S[i - 1] == 'R' && S[i] == 'L'){
			count++;
		}
	}
	int corner = 0;
	if(S[0] == 'L'){
		corner++;
	}
	if(S[N - 1] == 'R'){
		corner++;
	}
	if(count >= K){
		count -= K;
		K = 0;
	}
	else{
		count = 0;
		K -= count;
		corner = max(0, corner - K);
	}
	printf("%d\n", N - max(1, 2 * count + corner));
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
    int n=0,a=0,b=0,max=0;
    char s[101];
    scanf("%d %s", &n, s);
    for(a=0; a<n; a++){
        if(s[a]=='I')
            b++;

        else
            b--;

        if(max<b)
            max=b;

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;
typedef vector<int> vec;

int main(){
  string s;
  cin >> s;
  if(s[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  int n = s.size();
  int cnt = 0;
  for(int i=2;i<=n-1-1;i++){
    if(s[i]=='C') cnt ++;
  }
  if(cnt != 1){
    cout << "WA" << endl;
    return 0;
  }
  map<char,int> mp;
  for(char c : s)mp[c] ++;
  string T = "BDEFGHIJKLMOPQRSTUVWXYZ";
  for(char c : T){
    if(mp[c] > 0){
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;



int main()
{
	unsigned long long n;
	cin >> n;
	if ((n % 2) == 1) {
		cout << 0;
	}
	else {
		unsigned long long n2 = n / 2;
		unsigned long long res = 0;
		unsigned long long nn = 5;
		while (nn <= n2) {
			res += (n2 - n2 % nn) / nn;
			nn *= 5;
		}
		cout << res;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	long long a, b, sum, temp;
	while(scanf("%lld %lld",&a,&b) != EOF)
	{
		if(a < b){
			temp = a;
			a = b;
			b = temp;
		}
		sum = a * b;
		while(b != 0)
		{
			a %= b;
			temp = a;
			a = b;
			b = temp;
		}
		printf("%lld %lld\n",a,sum/a);
	}
	return 0;
}

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

using ll = long long;
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
#define swap(x, y)    \
  {                   \
    auto ___temp = x; \
    x = y;            \
    y = ___temp;      \
  }

const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}

ll bc(ll x, int i) {
  ll p = pow(2ll, i + 1), ph = p / 2;
  return x / p * ph + max(0ll, x % p + 1 - ph);
}
int main() {
  ll a, b;
  cin >> a >> b;
  ll re = 0;
  repr(i, (a - 1) / 4 * 4, a) re ^= i;
  repr(i, b / 4 * 4, b + 1) re ^= i;
  cout << re << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int X = sc.nextInt();
			int Y = sc.nextInt();
			int Z = sc.nextInt();

			int i = 0;
			while (true) {
				if (X < (Y * i + (Z * (i + 1)))) {
					i--;
					break;
				}
				i++;
			}
			System.out.println(i);
		}
	}
}


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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool f = true;
    int n = s.size();
    rep(i, 0, n){
        rep(j, i + 1, n){
            if(s[i] == s[j]) f = false;
        }
    }
    if(f) cout << "yes" << endl;
    else cout << "no" << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> p(n);
  for(int i = 0;i < n;i++){
    cin >> p[i];
    a[i] = (i + 1) * n;
    b[i] = n * (n - i);
  }
  for(int i = 0;i < n;i++){
    b[p[i] - 1] += (i + 1);
  }

  for(auto i : a){
    cout << i << ' ';
  }cout << endl;
  for(auto i : b){
    cout << i << ' ';
  }cout << endl;
}


Measured memory_bytes: 896
url = "https://atcoder.jp/contests/abc088/tasks/abc088_b"

def main():
    g = input()
    lis = list(map(int, input().split()))
    lis.sort(reverse=True)
    a = 0
    b = 0
    for i in range(len(lis)):
        if i % 2 == 0:
            a += lis[i]
        else:
            b += lis[i]
    print(a - b)


if __name__ == '__main__':
    main()




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

int main()
{
  char a,b,c,d;
  int A,B,C,D;
  scanf("%c%c%c%c",&a,&b,&c,&d);
  A = a-'0'; B = b-'0'; C = c-'0'; D = d-'0';
  // +++ 000
  if(A+B+C+D == 7) printf("%d+%d+%d+%d=7\n", A,B,C,D);
  // ++- 001
  else if(A+B+C-D == 7) printf("%d+%d+%d-%d=7\n", A,B,C,D);
  // +-+ 010
  else if(A+B-C+D == 7) printf("%d+%d-%d+%d=7\n", A,B,C,D);
  // +-- 011
  else if(A+B-C-D == 7) printf("%d+%d-%d-%d=7\n", A,B,C,D);
  // -++ 100
  else if(A-B+C+D == 7) printf("%d-%d+%d+%d=7\n", A,B,C,D);
  // -+- 101
  else if(A-B+C-D == 7) printf("%d-%d+%d-%d=7\n", A,B,C,D);
  // --+ 110
  else if(A-B-C+D == 7) printf("%d-%d-%d+%d=7\n", A,B,C,D);
  // --- 111
  else if(A-B-C-D == 7) printf("%d-%d-%d-%d=7\n", A,B,C,D);
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
list_PY = [ list(map(int,input().split(" "))) for i in range(m)]

for i in range(m):
    l = list_PY[i]
    l.append(i)
list_PY.sort(key=lambda x:(x[0], x[1]))

cnt = 0
k = 0
for i in range(m):
    l = list_PY[i]
    if l[0] == k:
        cnt += 1
        a = len(list(str(l[0])))
        b = "0"*(6 - a) + str(l[0])
        c = len(list(str(cnt)))
        d = "0"*(6 - c) + str(cnt)
    else:
        k = l[0]
        cnt = 1
        a = len(list(str(l[0])))
        b = "0" * (6 - a) + str(l[0])
        c = len(list(str(cnt)))
        d = "0" * (6 - c) + str(cnt)
    l.append(b+d)


list_PY.sort(key=lambda x:x[2])

for i in range(m):
    print(list_PY[i][3])

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

int main() {
	long long n, p;
	scanf("%lld %lld", &n, &p);
	vector<pair<long long,long long>> facs;
	for (long long i = 2; i * i <= p; ++i) if (p % i == 0) {
		long long cnt = 0;
		while (p % i == 0) {
			cnt++; p /= i; 
		}
		facs.push_back(make_pair(i, cnt));
	}
	if (p > 1) facs.push_back(make_pair(p, 1));
	long long ans = 1;
	for (auto v : facs) {
		long long cp = v.first;
		long long cnt = v.second / n;
		while (cnt--) {
			ans *= cp;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll h;

ll f(ll x) {
	if (x == 1)
		return 1;
	return f(x/2) * 2 + 1;
}
int main() {
	cin >> h;
	cout << f(h) << endl;
	return 0;
}


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

bool is_prime(int a){
  if(a == 1) return false;
  if(a == 2) return true;
  for(int i = 2; i < a; i++){
    if(a % i == 0){
      return false;
    }
  }
  return true;
}

int main(){
  int a;
  cin >> a;
  while(true){
    if(is_prime(a)){
      cout << a << endl;
      return 0;
    }
    a++;
  }
}

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

int main(){
	long long N,M,ans;
	cin>>N>>M;
	if(N>M)swap(N,M);
	if(N==1){
		if(M==1)ans=1;
		else ans=M-2;
	}else if(N==2){
		ans=0;
	}else{
		ans=(N-2)*(M-2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define int long long
#define MAX 1000000000000000000LL
int inf=100000000000007;
using namespace std;
typedef pair<int,int> P;
string alph="abcdefghijklmnopqrstuvwxyz";

signed main(){
    int n,m,k;cin>>n>>m>>k;
    int count=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            count=i*m+j*n-2*i*j;
            if(count==k){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

int main() {
	/*
cout<<"Hello World"<<endl;

	int x;
	cin>> x;
	cout<< x*x*x <<endl;

int a;
int b;
cin>>a>>b;
cout<<a*b<<" "<<2*a+2*b<<endl;

	int a;
	int b;
	cin>>a>>b;
	if (a<b){
		cout<< "a < b" <<endl;
	}else if(a>b){
		cout<<"a > b" <<endl;
	}else if(a==b){
		cout<<"a == b"<<endl;
	}else{

	}
	int a;
	int b;
	int c;
	cin>>a>>b>>c;
	if (a<b&&b<c){
		cout<<"Yes"<<endl;
	}else {
		cout<<"No"<<endl;
	}

	int a;
	int b;
	int c;
	int d;
	cin>>a>>b>>c;
	if(a>b){
	d=b;
	b=a;
	a=d;
	}
	if(b>c){
	d=c;
	c=b;
	b=d;
	}
	if(a>b){
	d=b;
	b=a;
	a=d;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
*/
	int W;
	int H;
	int x;
	int y;
	int r;
	int f1;
	int f2;
	int f3;
	int f4;
	cin>>W>>H>>x>>y>>r;

	bool t = false;

	if (x-r>=0){
		if(t) cout<<"1Yes"<<endl;
		f1=1;
	}else if (x-r<0){
		if(t) cout<<"1No"<<endl;
		f1=0;
	}
	if (y+r<=H){
		if(t) cout<<"2Yes"<<endl;
		f2=1;
	}else if (y+r>H){
		if(t) cout<<"2No"<<endl;
		f2=0;
	}
	if (x+r<=W){
		if(t) cout<<"3Yes"<<endl;
		f3=1;
	}else if (x+r>W){
		if(t) cout<<"3No"<<endl;
		f3=0;
	}
	if (y-r>=0){
		if(t) cout<<"4Yes"<<endl;
		f4=1;
	}else if (y-r<0){
		if(t) cout<<"4No"<<endl;
		f4=0;
	}
	if (f1==1&&f2==1&&f3==1&&f3==1&&f4==1){
		cout<<"Yes"<<endl;
	}else {
		cout<<"No"<<endl;
	}




	return 0;
}

Measured memory_bytes: 1156
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define lc (o << 1)
#define rc (o << 1 | 1)
#define mid ((l+r) >> 1)
using namespace std;
typedef pair<int,int> P;

const int maxn = 100009;
int T[maxn<<2], lazy[maxn<<2];
vector<P> q[maxn];
int n, m, cnt = 0, a, b, ans;

inline int read(){
	char ch = getchar(); int x = 0;
	while (ch < '0' || '9' < ch) ch = getchar(); 
	while ('0' <= ch && ch <= '9') { x = x*10+ch-'0'; ch = getchar(); }
	return x;
}

void pushdown(int o, int l, int r){
	if (!lazy[o]) return;
	T[lc] += lazy[o]*(mid-l+1);
	lazy[lc] += lazy[o];
	T[rc] += lazy[o]*(r-mid);
	lazy[rc] += lazy[o];
	lazy[o] = 0;
}

int query(int o, int l, int r, int x){
	if (l == r) return T[o];
	pushdown(o, l, r);
	if (x <= mid) return query(lc, l, mid, x);
	return query(rc, mid+1, r, x);
}

void update(int o, int l, int r, int x, int y){
	if (l == x && y == r){
		T[o] += r-l+1;
		lazy[o]++;
		return;
	}
	pushdown(o, l, r);
	if (x <= mid) update(lc, l, mid, x, min(y, mid));
	if (mid+1 <= y) update(rc, mid+1, r, max(x, mid+1), y);
}

int main(){
	n = read(); m = read();
	for (int i=1; i<=n; i++){
		a = read(); b = read();
		q[b-a+1].push_back(make_pair(a, b));
	}
	for (int i=1; i<=m; i++){
		ans = n-cnt;
		for (int j=i; j<=m; j+=i)
			ans += query(1, 1, m, j);
		printf("%d\n", ans);
		for (int j=q[i].size()-1; j>=0; j--){
			P t = q[i][j];  cnt++;
			update(1, 1, m, t.first, t.second);
		}
	}
	return 0;
}


Measured memory_bytes: 10240
def main():
    n=int(input())
    a=list(map(int,input().split()))
    tmp1=0
    tmp2=0
    low=0
    high=n-1
    while low!=high:
        if tmp1<tmp2:
            tmp1+=a[low]
            low+=1
        else:
            tmp2+=a[high]
            high-=1
    if tmp1<tmp2:
        print(abs(tmp1+a[low]-tmp2))
    else:
        print(abs(tmp2+a[low]-tmp1))

    
if __name__=='__main__':
    main()


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

#define MAX 1000000

const int MOD = 1e9 + 7;

bitset<MAX> prime;
vector<int> primeList;

void sieve() {
    prime.set();
    prime[0] = prime[1] = 0;
    primeList.push_back(2);
    for (int i=4; i<MAX; i+=2)
        prime[i] = 0;
    for (int p=3; p<MAX; p+=2)
        if (prime[p]) {
            primeList.push_back(p);
            for (int i=p; i<=(MAX-1)/p; i+=2)
                prime[i*p] = 0;
        }
}

long long power(long long a, int b) {
    long long ret = 1;
    for (; b>0; b/=2) {
        if (b % 2) ret = ret * a % MOD;
        a = a * a % MOD;
    }
    return ret;
}

int a[10000];
map<int, int> pf;

void factor(int n) {
    pf.clear();
    for (int p : primeList) {
        if (p * p > n)
            break;
        while (n % p == 0) {
            pf[p]++;
            n /= p;
        }
    }
    if (n > 1)
        pf[n]++;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    sieve();

    int n;
    cin >> n;
    map<int, int> l;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        factor(a[i]);
        for (auto &p : pf)
            l[p.first] = max(l[p.first], p.second);
    }

    long long tot = 1;
    for (auto &p : l)
        tot = tot * power(p.first, p.second) % MOD;

    int ret = 0;
    for (int i=0; i<n; i++) {
        factor(a[i]);
        long long cur = tot;
        for (auto &p : pf)
            cur = cur * power(power(p.first, pf[p.first]), MOD - 2) % MOD;
        ret += cur;
        if (ret >= MOD)
            ret -= MOD;
    }

    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 4188
using System;
using System.Collections.Generic;
class P
{
    static int v;
    static long[] d;
    static int r;
    static Graph g;
    static long inf = long.MaxValue - 10000;
    static void Main()
    {
        string[] str = Console.ReadLine().Split();
        int e;
        v = int.Parse(str[0]);
        e = int.Parse(str[1]);
        r = int.Parse(str[2]);
        d = new long[v];
        g = new Graph();
        for (int i = 0; i < e; i++)
        {
            str = Console.ReadLine().Split();
            int s, t, d2;
            s = int.Parse(str[0]);
            t = int.Parse(str[1]);
            d2 = int.Parse(str[2]);
            g.SetEdge(s, t, d2);
        }
        BellmanFord(r);
        foreach (var i in d)
        {
            if (i == inf)
                Console.WriteLine("INF");
            else
                Console.WriteLine(i);
        }
    }
    static void BellmanFord(int s)
    {
        for (int i = 0; i < v; i++)
            d[i] = inf;
        d[s] = 0;
        for (int i = 0; i < v - 1; i++)
        {
            bool f = false;
            foreach (var e in g.edges)
            {
                if (d[e.goal] > d[e.start] + e.Length)
                {
                    d[e.goal] = d[e.start] + e.Length;
                    f = true;
                }
            }
            if (!f)
                break;
        }
    }
}
struct Edge
{
    public int start;
    public int goal;
    public int Length;
    public Edge(int s, int g, int l)
    {
        start = s;
        goal = g;
        Length = l;
    }
}
class Graph
{
    public List<Edge> edges = new List<Edge>();
    public void SetEdge(int s, int g, int l)
    {
        edges.Add(new Edge(s, g, l));
    }
}


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

int main()
{
  long long int i,j,k,l=0;
  long long int space;
  long long int N,M,X;
  long long int K;
  char S[256];
  scanf("%lld\n",&K);
  scanf("%s",S);
  
  i = strlen(S);
  if( i<=K ){
    printf("%s",S);
  }
  else{
    for( j=0;j<K;j++){
      printf("%c",S[j]);
    }
    printf("...\n");             
  }
  
  return 0; 
  
}

Measured memory_bytes: 3832
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;


int main(){
	int n;
	cin >> n;
	int temp = (n+1)/2;
	cout << setprecision(10) << (double)temp/n << endl;
	return 0;
}




Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import java.util.ArrayList;

class Point {
    double x,y;
    Point(double x,double y) {
	this.x = x;
	this.y = y;
    }
}

class Main {
    public static void main(String args[]) {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String buf;

	try {
	    ArrayList<Point> array = new ArrayList<Point>();
	    while ((buf = br.readLine())!=null) {
		StringTokenizer st = new StringTokenizer(buf,",");
		array.add(new Point(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())));
	    }
	    double S = 0;
	    for (int i=1;i<array.size()-1;i++) {
		double a = dist(array.get(0),array.get(i));
		double b = dist(array.get(i),array.get(i+1));
		double c = dist(array.get(0),array.get(i+1));
		double z = (a+b+c)/2;
	        S += Math.sqrt(z*(z-a)*(z-b)*(z-c));
	    }
	    System.out.println(S);
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }

    public static double dist(Point p1,Point p2) {
	return Math.sqrt(Math.pow(p2.x-p1.x,2)+Math.pow(p2.y-p1.y,2));
    }
}

Measured memory_bytes: 16936
s = input()
n = len(s)
cnt = 0
if s == s[::-1]:
    cnt += 1
idx = (n-1)//2
if s[:idx] == s[:idx][::-1]:
    cnt += 1
idx = (n+3)//2-1
if s[idx:] == s[idx:][::-1]:
    cnt += 1
print("Yes" if cnt == 3 else "No")


Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>

int main(void)
{
    double r, square, length;
    
    scanf("%lf", &r);
    
    square = M_PI * r * r;
    length = 2 * M_PI * r;
    
    printf("%f %f\n", square, length);
    
    return 0;
}

Measured memory_bytes: 648
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
int main(){
    std::string S;
    std::string T;

    std::cin >> S;
    std::cin >> T;

    T.erase(T.length()-1);

    if(S==T){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    //::system("pause");
}

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

using namespace std;
const int MAXN = 1e5 + 7;
const int INF = 1e9 + 7;

int dp[MAXN], a[MAXN];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    dp[i] = INF;
  }
  dp[1] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= min(k, i - 1); j++) {
      dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));   
    }
  }
  cout << dp[n] << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const ll INF = 1e9+1;
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 N;

int main() {

    cin >> N;
    N+=2;
    vector<int> A(N,0);
    for (int i = 1; i <= N-2; i++) cin >> A[i];
    
    vector<int> left(N+1,0), right(N+1,0);
    int tmp = 0;
    for (int i = 1; i < N; i++) {
        tmp += abs(A[i] - A[i-1]);
        left[i] = tmp; 
    }
    tmp = 0;
    for (int i = N-1; i >= 1; i--) {
        tmp += abs(A[i] - A[i-1]);
        right[i-1] = tmp;
    }



    for (int i = 1; i < N-1; i++) {
        cout << abs(A[i+1]-A[i-1]) + left[i-1] + right[i+1] << endl;
    }



}


Measured memory_bytes: 2432
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

const int N = 1e+5+5;
const int mo = 1e+9+7;

int n;
LL a[N];
LL A,B;
int f0[N],f1[N];

int add(int x,int y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	scanf("%d%lld%lld",&n,&A,&B);
	fo(i,1,n)scanf("%lld",&a[i]);
	f0[0]=f1[0]=1;
	int p0=1,p1=1,l0=-1,l1=-1,w0=0,w1=0;
	fo(i,2,n){
		while(w0<=i&&a[i]-a[w0+1]>=B)p0=add(p0,f0[++w0]);
		int tmp0=p0;
		if (a[i]-a[i-1]<A){fo(j,l0+1,i-1)f0[j]=0;l0=i-2;p0=0;}
		while(w1<=i&&a[i]-a[w1+1]>=A)p1=add(p1,f1[++w1]);
		int tmp1=p1;
		if (a[i]-a[i-1]<B){fo(j,l1+1,i-1)f1[j]=0;l1=i-2;p1=0;}
		f0[i-1]=add(f0[i-1],tmp1);f1[i-1]=add(f1[i-1],tmp0);
		if (i-1<=w0)p0=add(p0,tmp1);
		if (i-1<=w1)p1=add(p1,tmp0);
	}
	int ans=0;
	fo(i,0,n)ans=add(ans,add(f0[i],f1[i]));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#define N 100000
typedef struct{
  char s[10];
  int time;
  int process;
}data;
int main(){
  data a[N],b[N],c;
  int sum=0,t,d,i,j=0,head=0,tail;
  scanf("%d %d",&tail,&t);
  for(i=0;i<tail;i++){
    scanf("%s %d",a[i].s,&a[i].time);
    a[i].process=0;
  }
  while(head!=tail){
    if(a[head].time-t>=0){
      sum=sum + t;
      a[head].process=sum;
      a[head].time=a[head].time - t;    
    }
    else if(a[head].time-t<0){
      sum=sum + a[head].time;
      a[head].process=sum;
      a[head].time=0;
    }
    if(a[head].time==0){
      printf("%s %d\n",a[head].s,a[head].process);
      head++;
    }
    else{
      c=a[head];
      for(i=head;i<tail;i++){
	a[i]=a[i+1];
      }
      a[tail-1]=c;
    }	
  }
  return 0;
}
      



Measured memory_bytes: 2752
N,K,Q=map(int,input().split())
A=[]
ans=[]
re_ans=""
for i in range(Q):
    A.append(int(input()))
while N>0:
    ans.append(K)
    N-=1
for j in A:
    ans[j-1]=ans[j-1]+1
for k in ans:
    if k-len(A)>0:
        re_ans+="Yes\n"
    else:
        re_ans+="No\n"
print(re_ans.rstrip("\n"))

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

const int _ = 1e5 + 7;
int N , col[_] , num[_]; vector < int > nxt[_];
struct Tree{
	struct Edge{int end , upEd;}Ed[_ << 1];
	int head[_] , cntEd;
	void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd;}

	int dfs(int x){
		int pre = 0;
		for(int i = head[x] ; i ; i = Ed[i].upEd){
			num[x] ^= 1; int t = dfs(Ed[i].end);
			if(!pre) pre = t; else{nxt[pre].push_back(t); nxt[t].push_back(pre); pre = 0;}
		}
		return !pre ? x : pre;
	}

	void work(){
		int rt; for(int i = 1 , x ; i <= N ; ++i){cin >> x; if(x == -1) rt = i; else addEd(x , i);}
		rt = dfs(rt); nxt[rt].push_back(rt);
	}
}T1 , T2;

void color(int x , int c){col[x] = c * 2 - 1; for(auto t : nxt[x]) if(!col[t]) color(t , c ^ 1);}

int main(){
	cin >> N; T1.work(); T2.work(); bool flg = 1;
	for(int i = 1 ; i <= N ; ++i) flg &= !num[i];
	if(!flg) puts("IMPOSSIBLE");
	else{
		puts("POSSIBLE"); for(int i = 1 ; i <= N ; ++i) if(!col[i] && !nxt[i].empty()) color(i , 0);
		for(int i = 1 ; i <= N ; ++i) printf("%d " , col[i]);
	}
	return 0;
}


Measured memory_bytes: 11776
# 分岐を改良
from collections import deque

S = deque(list(input()))
Q = int(input())

# flag = 0
flag = False  # フラグをブール値で。 Trueのとき反転
for i in range(Q):
    query = input().split()

    if query[0] == '1':
        # flag = flag ^ 1
        flag = not flag
        continue

    if query[0] == '2':
        if (query[1] == '1' and flag is False) or (query[1] == '2' and flag is True):
            S.appendleft(query[2])
        else:
            S.append(query[2])

if flag is True:
    # deque型はスライスで取り出せない print(''.join(S[::-1]))
    S.reverse()
print(''.join(S))

Measured memory_bytes: 8804
#include <iostream>

int F[100][10];
int P[100][11];

using namespace std;
int main(){
    int n;
    std::cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin >> F[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin >> P[i][j];
        }
    }
    int res = -(1 << 30);
    for(int b=1;b<(1<<10);b++){
        int tmp = 0;
        for(int i=0;i<n;i++){
            int op_cnt = 0;
            for(int j=0;j<10;j++){
                if(((b>>j)&1)==1 && F[i][j] == 1){
                    op_cnt++;
                }
            }
            tmp += P[i][op_cnt];
            // cout << tmp << endl;
        }
        res = max(res, tmp);
    }
    cout << res << endl;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    nums = []
    n6 = 6
    while n6 <= n:
        nums.append(n6)
        n6 = n6 * 6
    n9 = 9
    while n9 <= n:
        nums.append(n9)
        n9 = n9 * 9
    nums.sort(reverse=True)
    dp = [i for i in range(2 * n + 1)]
    for num in nums:
        for j1 in range(n + 1):
            dp[j1+num] = min(dp[j1+num], dp[j1] + 1)
    print(dp[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 79400
N, K, Q = gets.split(" ").map(&:to_i)
points = Array.new(N, K)

Q.times do |i|
    A = gets.to_i
    points[A - 1] += 1
end

points.each do |p|
    p -= Q
    if p <= 0
        puts "No"
    else
        puts "Yes"
    end
end

Measured memory_bytes: 3964
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int[] list = new int[6];
    for (int i = 0; i < 6 ; i++ ) {
      list[i] = sc.nextInt();
    }

    int a = list[0];
    int e = list[4];
    int k = list[5];

    if (e - a > k) {
      System.out.println(":(");
    } else {
      System.out.println("Yay!");
    }
  }
}


Measured memory_bytes: 19924
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    CIN(N);
    string str;cin >> str;
    int ins = 0,ans = 0;
    REP(i,N){
        if(str.at(i)=='I'){
            ins++;
        }else{
            ins--;
        }
        ans = max(ans,ins);
    }
    COUT(ans);
    return 0;
}


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

using namespace std;

int main()
{
    long long int n,ans=0;
    cin >> n ;
    for (long long int i = 1; n>i*i+i; i++)
    {
        if (n%i == 0)
        {
            ans += n/i-1;
        }
        
    }
    cout << ans <<endl;
    return 0;
    
}

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

#define rep(i,x) for(int i=0;i<x;i++)
using namespace std;

//x^n
int pow(int x, int n){
    if (n == 0) return 1;
    int y = pow(x, n / 2);
    y *= y;
    if (n % 2 == 1) y *= x;
    return y;
}

int main(){
    int n, m; cin >> n >> m;
    vector<pair<int, int>> SCs(m);
    rep(i, m){
        int s, c; cin >> s >> c;
        SCs[i].first = s - 1;
        SCs[i].second = c;
    }
    int ceil = pow(10, n);
    int floor = pow(10, n - 1);
    if (floor == 1) floor = 0;
    int INF = pow(10, 5);
    int ans = INF;
    for (int i = floor; i < ceil; i++){
        string str = to_string(i);
        bool allok = true;
        for (auto sc : SCs){
            char charC = sc.second + '0';
            if (str[sc.first] != charC){
                allok = false;
            }
        }
        if (allok) ans = min(i, ans);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  vector<int> b(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(b.begin(),b.end());
  int med1=b[N/2];
  int med2=b[N/2-1];
  for(int i=0;i<N;i++){
    if(med1==med2){
      cout<<med1<<endl;
    }
    else{
      if(med1<=a[i]){
        cout<<med2<<endl;
      }
      else{
        cout<<med1<<endl;
      }

    }
  }

}


Measured memory_bytes: 3712
using System;
public class Hello{
    static int Calc(string a,string b,string c){
        int A = int.Parse(a);
        int B = int.Parse(b);
        int C = int.Parse(c);
        
        return (A - C) / (B + C);
    }
    public static void Main(){
        string[] input = Console.ReadLine().Split(' ');
        int ans = Calc(input[0],input[1],input[2]);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
n,k=map(int,input().split())
s=input()
t=list()
ans=0
count=1
for i in range(n-1):
	if s[i]==s[i+1]:
		count+=1
	else:
		if count >= 2:
			ans += count-1
		t.append(1)
		count=1
if count >= 2:
	ans += count-1
t.append(1)
if len(t) < 2*k+1:
	ans += len(t) - 1
else:
	ans += 2*k
print(ans)

Measured memory_bytes: 3956
#include<stdio.h>
#include<math.h>
#define PI 3.14159265358979

int main(){
  double ans;
  int a, b, x;
  scanf("%d%d%d", &a, &b, &x);

  if (x<=a*a*b/2) {
    //    ans = atan(a*b*b/x/2.0);
    ans = atan2(b, x*2.0/a/b);
    //    ans = atan(a*b*b/x/2.0);
  } else {
    //    ans = atan((x-a*a*b)*2.0/a/a);
    //    ans = atan2((x*1.0/a-a*b)*2.0/a, a);
    // ans = atan2((a*b-x*1.0/a)/a*2, a);
     ans = atan((a*b-x*1.0/a)/a*2/a);
  }
 
    ans = (ans*180)/M_PI;
    // ans = (ans*180)/PI;
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

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

    int tmp, count, ans = n;

    for (int i = 0; i <= n; i++) {
        count = 0;

        tmp = i;
        while (tmp > 0) {
            count += tmp % 6;
            tmp /= 6;
        }

        tmp = n - i;
        while (tmp > 0) {
            count += tmp % 9;
            tmp /= 9;
        }

        ans = min(ans, count);
    }

    cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N+1);
    vector<int> f(N+1,0);
    for(int i=1;i<=N;++i) cin >> a[i];
    int ans = 0;
    for(int i=N;i>=1;--i){
        int cnt = 0;
        for(int j=i*2;j<=N;j+=i){
            cnt += f[j];
        }
        if(cnt%2 != a[i]) {
            ++f[i];
            ++ans;
        }
    }
    cout << ans << endl;
    rep(i,N) {
        if(f[i+1]) cout << i+1 << " ";
    }
    if(ans >= 1)cout << endl;
}

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

int main(){ 
    Int X;
    cin >> X;

    vector<Int> n(4000);

    n[0] = 100;

    int ans;

    rep(i,3999) {
        n[i+1] = n[i] + (n[i] / 100);
        if (n[i+1] >= X) {
            ans = i+1;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3660
N = int(input())
A = list(map(int,input().split()))
counts = [0 for _ in range(N)]
for a in A:
  counts[a-1]+=1
ans = 0
for count in counts:
  ans += count*(count-1)
ans //= 2
for i in range(N):
  print(ans - counts[A[i]-1] + 1)
  

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

void solve () {
	ll n;
	cin >> n;
	vector <ll> adj[n + 1];
	ll u, v;
	for (ll i = 0; i < n - 1; i++) {
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	ll ans = 0;
	ll arr[n + 1];
	ll cnt = 0;
	for (ll i = 1; i <= n; i++) {
		cnt++;
		ll g = 0, h = 0, mn = n + 1;
		for (auto j : adj[i]) {
			if (j < i) {
				g++;
			}
			else {
				mn = min(mn, j);
			}
		}
		cnt -= g;
		ans += cnt;
		if (mn == n + 1) {
			h = - (n - i + 1);
		}
		else {
			h = - (mn - i);
		}
		for (auto j : adj[i]) {
			if (j > mn) {
				h += n - j + 1;
			}
		}
		arr[i] = h;
	}
	ll x = ans;
	for (ll i = 2; i <= n; i++) {
		ans += x + arr[i - 1];
		x += arr[i - 1];
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
  #endif
	int t = 1;
	while (t--) {
		solve();
	}
 	return 0;
}

Measured memory_bytes: 17344
R, G, B, N = map(int, input().split())
cnt = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        if (N - R * i - G * j) / B >= 0 and ((N - R * i - G * j) / B) % 1 == 0:
            cnt += 1
print(cnt)

Measured memory_bytes: 40684