akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
C = [[0] * w for _ in range(h)]
i = 0
j = 0
for k, a in enumerate(A):
    for _ in range(a):
        C[i][j] = k + 1

        if i % 2 == 0:
            if j < w - 1:
                j += 1
            else:
                i += 1
        else:
            if j > 0:
                j -= 1
            else:
                i += 1
for row in C:
    print(*row)


Measured memory_bytes: 3916
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;
int main()
{

    int a;
    cin >> a;

    for(int i=1;i<10;i++)
        for (int j = i ; j < 10; j++)if (a == i * j) {

            cout << "Yes" << endl;
            return 0;
        }
    cout << "No" << endl;
   
   
    return 0;

}


Measured memory_bytes: 256
hand = raw_input()
hands = [_ for _ in hand]
g = 0
p = 0
point = 0
for _ in range(len(hand)):
	if _%2 == 0:
		if hands[_] == 'p':
			point -= 1
	else:
		if hands[_] == 'g':
			point += 1

print point

Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ll n, w;
    cin >> n >> w;
    vector<vector<int> > values(4);
    ll w1, v1;
    cin >> w1 >> v1;
    values[0].push_back(v1);

    for (int i = 1; i < n; i++) {
        ll w, v;
        cin >> w >> v;
        values[w - w1].push_back(v);
    }

    for (int i = 0; i < 4; i++) {
        sort(values[i].begin(), values[i].end());
        reverse(values[i].begin(), values[i].end());
    }

    vector<vector<ll> > sum(4);
    for (int i = 0; i < 4; i++) {
        sum[i].assign(values[i].size() + 1, 0);
        for (int j = 0; j < values[i].size(); j++) {
            sum[i][j + 1] = sum[i][j] + values[i][j];
        }
    }

    ll ans = 0;
    for (int i = 0; i <= values[0].size(); i++) {
        for (int j = 0; j <= values[1].size(); j++) {
            for (int k = 0; k <= values[2].size(); k++) {
                for (int l = 0; l <= values[3].size(); l++) {
                    if (i * w1 + j * (w1 + 1) + k * (w1 + 2) + l * (w1  + 3) <= w) {
                        ans = max(ans, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
                    }
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int main(){
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    if(n==1){
        if(a!=b)  printf("0\n");
        else  printf("1\n");
    }
    else{
        if(a>b)  printf("0\n");
        else printf("%lld\n",(long long)(n-2)*(b-a)+1);
    }

    return 0;
}


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n;
    cin >> n;
    i64 a, b;
    cin >> a >> b;
    i64 x = 0, y = 0, z = 0;
    for (i64 i = 0; i < n; i++) {
        i64 p;
        cin >> p;
        (p <= a ? x : p <= b ? y : z)++;
    }
    cout << min({ x, y, z }) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

int main() {
	long H,p;
	int N;
	p=0;
	cin >>H>>N;

	int A[N+1];
	for(int i=1;i<=N;i++){
		cin >> A[i];
		p+=A[i];
	}
	if(p>=H){
		cout << "Yes"<<endl;
	}
	else{
		cout <<"No"<<endl;
	}

	

}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;

struct point3d {
	double x;
	double y;
	double z;
};

point3d polar_to_point3d(double latitude_rad, double longitude_rad, double r)
{
	point3d p;

	p.x = r * cos(longitude_rad) * cos(latitude_rad);
	p.y = r * sin(longitude_rad) * cos(latitude_rad);
	p.z = r * sin(latitude_rad);

	return p;
}

double get_distance(const point3d& p1, const point3d& p2)
{
	return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2) + pow(p1.z - p2.z, 2));
}

double deg_to_rad(double deg) {
	return M_PI * deg / 180.0;
}

int main()
{
	static const double r = 6378.1;
	double a, b, c, d;

	while (cin >> a >> b >> c >> d) {
		if (a == -1 && b == -1 && c == -1 && d == -1) {
			break;
		}

		point3d p1 = polar_to_point3d(deg_to_rad(a), deg_to_rad(b), r);
		point3d p2 = polar_to_point3d(deg_to_rad(c), deg_to_rad(d), r);

		double dist = get_distance(p1, p2);
		double cos_theta = 1 - dist * dist / (2 * r * r);
		double l = r * acos(cos_theta);

		cout << lround(l) << endl;
	}
}

Measured memory_bytes: 1276
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1100000, INF = 0x7fffffff, MOD = 1e9 + 7;

LL D[maxn], U[maxn];
LL q_pow(LL a, LL b)
{
    LL ret = 1;
    while(b)
    {
        if(b & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ret;
}

void init()
{
    U[0] = D[0] = 1;
    for(int i = 1; i < maxn; i++)
    {
        U[i] = U[i - 1] * i % MOD;
        D[i] = q_pow(U[i], MOD - 2);
    }
}

LL C(LL n, LL m)
{
    return U[n] * D[m] % MOD * D[n - m] % MOD;
}

int main()
{
    init();

    LL h, w, a, b, ret = 0;
    cin >> h >> w >> a >> b;
    for(int i = b + 1; i <= w; i++)
    {
        ret = (ret + C(h - a + i - 2, i - 1) * C(a - 1 + w - i, a - 1)) % MOD;
     //   cout << C(h - a + i - 2, i - 1) << "    " << C(a - 1 + w - i, a - 1) << endl;
    }
   ret = (ret % MOD + MOD) % MOD;
   cout << ret << endl;




	return 0;
}


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

using namespace std;
using ll = long long;
constexpr ll INF = 1e17;

int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<ll>> dist(n, vector<ll>(n, INF));

    for(int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = dist[b][a] = c;
    }
    for(int i = 0; i < n; i++)dist[i][i] = 0;
    

    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    

    vector<vector<int>> ans(n, vector<int>(n));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans[i][j] = (dist[i][j] <= l ? 1 : 1e9);
        }
    }
    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);
            }
        }
    }

    int q;
    cin >> q;
    vector<int> s(q), t(q);

    for(int i = 0; i < q; i++) {
        cin >> s[i] >> t[i];
        s[i]--, t[i]--;
    }

    for(int i = 0; i < q; i++) {
        cout << (ans[s[i]][t[i]] >= 1e9 ? -1 : ans[s[i]][t[i]] - 1) << endl;
    }

}

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

int main(){
    int n, k, i, m = 2000000000;
    cin >> n >> k;
    int h[n];
    for(i=0; i<n; i++){
        cin >> h[i];
    }
    sort(h, h+n);
    for(i=0; i<=n-k; i++){
        m = min(m, h[i+k-1]-h[i]);
    }
    cout << m;
    return 0;
}

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

using namespace std;
int main(){
    long long N;
    cin>>N;
    long long p[N][3];
    long long dpa[N+1];
    long long dpb[N+1];
    long long dpc[N+1];
    for(int i=0;i<N;++i){
        cin>>p[i][0]>>p[i][1]>>p[i][2];
        dpa[i]=1000000002, dpb[i]=1000000002, dpc[i]=1000000002;
    }

    dpa[0]=p[0][0],dpb[0]=p[0][1], dpc[0]=p[0][2];

    for(int i=1;i<N;++i){
        dpa[i]=max(dpb[i-1]+p[i][0],dpc[i-1]+p[i][0]);
        dpb[i]=max(dpa[i-1]+p[i][1],dpc[i-1]+p[i][1]);
        dpc[i]=max(dpb[i-1]+p[i][2],dpa[i-1]+p[i][2]);
    }
    cout<<max(dpa[N-1],max(dpb[N-1],dpc[N-1]))<<endl;
}

Measured memory_bytes: 8276
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

double dp[3005][3005] ={};
signed main() {
	int n;
	cin>>n;

	vector<double> a(n);cin>>a;

	dp[0][0]=1;
	rep(i,n){
		rep(j,n){
			dp[i + 1][j + 1] += dp[i][j] * a[i];
			dp[i + 1][j] += dp[i][j] * (1.00 - a[i]);
		}
	}

	//rep(i,n  +1){ rep(j,n + 1){ cout << dp[i][j] << ' '; } cout << endl; }

	double sum = 0;
	rep(i,n + 1){
		if(i > n - i) sum += dp[n][i];
	}
	cout << fixed << setprecision(10) << sum << endl;
}


Measured memory_bytes: 70656
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  ll n, m, a, b, ans = 0, k;
  cin >> n >> m >> k;
  vector<ll> suma(n + 10), sumb(m + 10);
  for (int i = 0; i < n; i++) {
    cin >> a;
    suma[i + 1] = suma[i] + a;
  }
  for (int i = 0; i < m; i++) {
    cin >> b;
    sumb[i + 1] = sumb[i] + b;
  }
  for (int i = 0; i <= n; i++) {
    while (m >= 0 && suma[i] + sumb[m] > k) {
      m--;
    }
    if (m >= 0) {
      ans = max(ans, i + m);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6420
use proconio::input;

fn f(x: usize) -> usize {
    let mut res = 0;
    let mut x = x;
    while x > 0 {
        res += x % 10;
        x /= 10;
    }
    res
}

fn main() {
    input! {
        n: usize,
    };
    let ans = n % f(n) == 0;
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2112
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int inf=1e9+7;
    
int main()
{
   	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int n;
    while(cin>>n)
    {
    	double num;
    	
    	priority_queue<double,vector<double>,greater<double> >q;
    	
    	for(int i=0;i<n;i++)
    	{
    		cin>>num;
    		q.push(num);
		}
		
		while(q.size()>1)
		{
			double a=q.top();
			q.pop();
			double b=q.top();
			q.pop();
			
			q.push((a+b)/2);
		}
		
		cout<<q.top()<<endl;
	}
    
    return 0;
}

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

using namespace std;

void swap ( vector<string> &v, int i, int j )
{
	string tmp = v[i];
	v[i] = v[j];
	v[j] = tmp;
}

vector<string> BubbleSort ( vector<string> v )
{

	int i,j;
	for ( i = 0 ; i < v.size()-1 ; i++ )
	{
		for ( j = v.size()-1 ; i < j ; j-- )
		{
			if ( v[j-1][1] > v[j][1] )
			{
				swap ( v, j-1, j );
			}
		}
	}

	return v;
}

vector<string> SelectionSort ( vector<string> v )
{

	int i,j,min_index;

	for ( i = 0 ; i < v.size() ; i++ )
	{
		min_index = i;
		for ( j = i ; j < v.size() ; j++ )
		{
			if ( v[min_index][1] > v[j][1] )
			{
				min_index = j;
			}
		}
		if ( min_index != i )
		{
			swap ( v, min_index, i );
		}
	}
	
	return v;
}

void show ( vector<string>& v )
{
	int i;
	for ( i = 0 ; i < v.size()-1 ; i++ )
	{
		cout << v[i] << " ";
	}
	cout << v[i] << endl;
}

int main () 
{

	vector<string> v,Bubble,Selection;
	int N;
	string n;

	cin >> N;

	while ( N-- )
	{
		cin >> n;
		v.push_back ( n );
	}

	Bubble =  BubbleSort(v);
	Selection = SelectionSort(v);

	show ( Bubble );
	cout << "Stable" << endl;
	show ( Selection );
	if ( Bubble == Selection )
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}

return 0;
}



Measured memory_bytes: 3192
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<int> a(n); rep(i, n)cin >> a[i];
	vector<bool> dp(k + 1, false);
	rep(i, k + 1)rep(j, n)
	{
		if (i - a[j] < 0)continue;
		if (!dp[i - a[j]])dp[i] = true;
	}
	if (dp[k])cout << "First" << endl;
	else cout << "Second" << endl;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main(void){
   int N;
   int Y;
   scanf("%d%d", &N,&Y);
   int x,y,z;
   for (x = 0; x < N+1; x++) {
      for ( y = 0; y < 9; y++) {
         z = N - x - y;
         if (z < 0) {
            break;
         }else{
            if (x*10000 + y*5000 + z*1000==Y) {
               printf("%d %d %d\n",x,y,z);
               return 0;
            }
         }
      }
   }
   printf("-1 -1 -1\n");
   return 0;

}


Measured memory_bytes: 128
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }.toIntArray()

  var count = 0
  for (i in 0 until n) {
    var ai = a[i]
    while (ai % 2 == 0) {
      count++
      ai = ai / 2
    }
  }
  println(count)
}

Measured memory_bytes: 40868
#include <iostream>
#include <vector>
#include <string>
#define input std::cin

using vector = std::vector<int>;
using lint = long long int;
using string = std::string;

int main() {
  int n; input >> n;
  int cnt = 0;
  for (int i=0; i<n; i++) {
	for (int j=1; j*j <= i; j++) {
	  if (i % j == 0) {
		if (j*j == i)
		  cnt ++;
		else
		  cnt += 2;
	  }
	}
  }
  std::cout << cnt << std::endl;
}



Measured memory_bytes: 3668
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
	int n;scanf("%d",&n);
	map<int,int> tb;
	for(int i = 2;i <= n;++i)
	{
		int x;scanf("%d",&x);
		++tb[x];
	}
	for(int i = 1;i <= n;++i)
		printf("%d\n",tb[i]);
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

// 最大公約数 : 3,4 ->  1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数 : 3,4 -> 12
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }


void solve()
{
	int a, b;
	cin >> a >> b;
	cout << lcm(a, b);
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long int ll;

const int N = 3e3 + 10;
const int M = 2e5 + 10;
const int mod = (int) 1e9 + 7;

int h, w, n;
int r[N], c[N];
int fact[M], ifact[M];
int memo[N];

int mult(ll a, ll b) {
  return (a * b) % mod;
}

int pw(int n, int k) {
  int ans = 1;
  while(k) {
    if(k % 2 == 0) {
      k /= 2;
      n = mult(n, n);
    } else {
      k--;
      ans = mult(ans, n);
    }
  }
  return ans;
}

int inv(int n) {
  return pw(n, mod - 2);
}

int choose(int n, int k) {
  return mult(fact[n], mult(ifact[k], ifact[n - k]));
}

int calc(int i, int j) {
  int dr = abs(r[i] - r[j]);
  int dc = abs(c[i] - c[j]);
  int tot = dr + dc;
  return choose(tot, dr);
}

int dp(int at) {
  if(at == n + 1) return 1;
  int &ans = memo[at];
  if(ans != -1) return ans;
  ans = calc(at, n + 1);
  for(int i = 0; i < n + 1; ++i) {
    if(r[at] <= r[i] && c[at] <= c[i] && i != at) {
      int ways = calc(i, at);
      int more = dp(i);
      int cur = mult(ways, more);
      ans = (ans - cur + mod) % mod;
    }
  }
  return ans;
}

void solve() {
  cin >> h >> w >> n;
  r[0] = c[0] = 1;
  for(int i = 1; i <= n; ++i) {
    cin >> r[i] >> c[i];
  }
  memset(memo, -1, sizeof(memo));
  r[n + 1] = h, c[n + 1] = w;
  fact[0] = ifact[0] = 1;
  for(int i = 1; i < M; ++i) fact[i] = mult(i, fact[i - 1]), ifact[i] = inv(fact[i]);
  int ans = dp(0);
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(9);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int MOD=1e9+7;
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(void)
{
    string s;
    cin >> s;
    if(s[0]!=s[1] || s[0]!=s[2] || s[1]!=s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
  int n; cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];

  int ans = 0;
  for (int i = 1; i < n - 1; i++)
  {
    if ((p[i + 1] - p[i]) * (p[i] - p[i - 1]) > 0) ans++;
  }

  cout << ans << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 079 D / Link: http://abc079.contest.atcoder.jp/tasks/abc079_d  ----- */


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

	LL H, W; cin >> H >> W;
	VVL d(10, VL(10));
	FOR(i, 0, 10) {
		FOR(j, 0, 10) {
			cin >> d[i][j];
		}
	}
	FOR(k, 0, 10)FOR(i, 0, 10)FOR(j, 0, 10) {
		d[i][j] = min(d[i][j], d[i][k]+ d[k][j]);
	}

	LL ans = 0LL;
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			LL in; cin >> in;
			if (in != -1) {
				ans += d[in][1];
			}
		}
	}
	
	
	cout << (ans) << "\n";

	return 0;
}


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


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

  string s;
  cin >> s;
  int n=s.size();
  int ans=0;
  rep(i,n){
    if(i>n-1-i) break;
    if(s[i]==s[n-1-i]) continue;
    else ans++;
  }
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
	
  string s;
  int a,b,c,d,i,j,k;
  
  cin >> a;
  cin >> b;
	
  if(a+b==15){
    cout <<"+" <<endl;
  }else if(a*b==15){
	cout <<"*" <<endl;
  }else{
    cout << "x" <<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
//temp##############################################

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

void strInit(char str[]);//str[]を0で初期化
void extIntStr(char str[],int data[]);//str[]から数値(int)を抽出しdata[]に順次格納
void incsort(int data[],int len);//data[]を昇順ソート
void decsort(int data[],int len);//data[]を降順ソート
void printIntArray(int data[],int len);//data[]をprint
int* inputArray(int n);//文字列を受け取り数値を抽出、n個の数値(int)を格納した配列のポインタをreturn

void strInit(char str[]){
    int len=strlen(str);
    for(int i=0;i<len;i++){
        str[i]=0;
    }
}

void extIntStr(char str[],int data[]){
    int length=strlen(str);
    str[length-1]=' ';
    char buff[12];
    int j,index;
    index=j=0;
    for(int i=0;i<length;i++){
        if(str[i]!=' '){
            buff[j++]=str[i];
        }else{
            data[index++]=atoi(buff);
            strInit(buff);
            j=0;
        }
    }
}

void incsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]>data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void decsort(int data[],int len){
    for(int i=0;i<len-1;i++){
        for(int j=i+1;j<len;j++){
            if(data[i]<data[j]){
                int tmp=data[i];
                data[i]=data[j];
                data[j]=tmp;
            }
        }
    }
}

void printIntArray(int data[],int len){
    for(int i=0;i<len;i++){
        printf("%d\n",data[i]);
    }
}

int* inputArray(int n){
    int *data;
    data=(int*)malloc(sizeof(int)*n);
    char *get;
    get=(char*)malloc(sizeof(char)*11*n+1);
    fgets(get,11*n+1,stdin);
    extIntStr(get,data);
    free(get);
    return data;
}

//temp##############################################

//don't forget free(data);

int main(){
    int n;
    scanf("%d ",&n);
    int *data;
    data=inputArray(n);
    int q=0;
    int i,j;
    int min=0;
    for(i=0;i<n;i++){
        min=i;
        for(j=i;j<n;j++){
            if(data[min]>data[j]){
                min=j;
            }
        }
        int tmp=data[min];
        data[min]=data[i];
        data[i]=tmp;
        if(data[i]!=data[min])q++;
    }
    if(q>1)printf("NO");
    else printf("YES");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a;
    cin >> a;
    cout << 48-a << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int s=0;
	int i;
	for(int i=1;i<=a;i++) {
		int t=i,f=0;
		while(t){
			t/=10;
			f++;
		}
		if(f%2) s++;
	}
	cout <<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repf(i, a, b) for(ll i = (a); i < (b) ; i++ )
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;
ll a[n] = {};
rep(i, n){
    cin >> a[i];
}
ll b[n] = {};
rep(i, n){
    cin >> b[i];
}
vector<ll> c(n);
vector<ll> d(n);
rep(i,30){
    rep(j,n){
        c[j]=b[j]&((1LL<<i+1)-1);
        d[j]=a[j]&((1LL<<i+1)-1);
    }
    sort(c.begin(),c.end());
    ll co=0;
    rep(j,n){
        ll k=1LL<<i;
        co+=upper_bound(c.begin(),c.end(), 2*k-1-d[j])-lower_bound(c.begin(),c.end(), k-d[j]);
        co+=upper_bound(c.begin(),c.end(),  4*k-1-d[j])-lower_bound(c.begin(),c.end(), 3*k-d[j]);
    }
    if(co%2)ans+=1LL<<i;
}

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

Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1)/ (y))

u64 X, Y, Z, K;
u64 *A, *B, *C;

int cmp(const void *a, const void *b);

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

    cin >> X >> Y >> Z >> K;
    A = new u64[X];
    B = new u64[Y];
    C = new u64[Z];
    rep(i, X)
    {
        cin >> A[i];
    }
    rep(i, Y)
    {
        cin >> B[i];
    }
    rep(i, Z)
    {
        cin >> C[i];
    }

    u64 *ApB = new u64[X * Y];
    rep (i, X)
    {
        rep (j, Y)
        {
            ApB[i * Y + j] = A[i] + B[j];
        }
    }
    qsort((void*)ApB, X * Y, sizeof(u64), cmp);

    u64 *ApBpC = new u64[MIN(K, X * Y) * Z];
    rep (i, Z)
    {
        rep (j, MIN(K, X * Y))
        {
            ApBpC[i * MIN(K, X * Y) + j] = C[i] + ApB[j];
        }
    }

    qsort((void*)ApBpC, Z * MIN(K, X * Y), sizeof(u64), cmp);

    rep (i, K)
    {
        cout << ApBpC[i] << "\n";
    }

    return 0;
}

int cmp(const void *a, const void *b)
{
    return (*(const u64*)b > *(const u64*)a) ? 1 : *(const u64*)b == *(const u64*)a ? 0 : -1;
}



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

using namespace std;

#define rep(i,n) for(int i=0; i < int(n); i++)

int main(){
    int n,l;
    cin >> n;
    cin >> l;
    vector<string> str(n);
    
    rep(i,n)
        cin >> str.at(i);
    
    sort(str.begin(),str.end());
    
    rep(i,n)
        cout << str.at(i);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

struct point
{
	ld x, y;
};

ld sqr(ld x)
{
	return x * x;
}

ld dist(point a, point b)
{
	return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}

vector<point> a;

bool check(ld x, ld y, ld r)
{
	for (int i = 0; i < a.size(); i++)
		if (dist({ x,y }, a[i]) > r)
			return false;
	return true;
}

ld ff(ld x,ld y)
{
	ld l = 0, r = 10000;
	ld eps = 0.0000000001;
	while (abs(r - l) > eps)
	{
		ld m = (l + r) / 2;
		if (check(x,y,m))
			r = m;
		else
			l = m;
	}
	return l;

}

ld f(ld x)
{
	ld yl = 0, yr = 1000;
	ld eps = 0.0000000001;
	while (abs(yr - yl) > eps)
	{
		ld m1 = yl + (yr - yl) / 3, 
			m2 = yr - (yr - yl) / 3;

		if (ff(x,m1) > ff(x,m2))
			yl = m1;
		else
			yr = m2;
	}

	return ff(x,yl);
}

void solve()
{
	int n;
	cin >> n;
	a = vector<point> (n);
	for (int i = 0; i < n; i++)
		cin >> a[i].x >> a[i].y;
	
	ld xl = 0, xr = 1000;
	
	ld eps = 0.0000000001;
	while (abs(xr-xl) > eps)
	{
		ld m1 = xl + (xr - xl) / 3, m2 = xr - (xr - xl) / 3;

		if (f(m1) > f(m2))
			xl = m1;
		else
			xr = m2;
	}

	ld x = xl;
	ld yl = 0, yr = 1000;
	while (abs(yr - yl) > eps)
	{
		ld m1 = yl + (yr - yl) / 3,
			m2 = yr - (yr - yl) / 3;

		if (ff(x, m1) > ff(x, m2))
			yl = m1;
		else
			yr = m2;
	}
	ld y = yl;
	cout <<fixed<<setprecision(8)<< ff(x, y);
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long t;
    int cc[n-1];
    int ss[n-1];
    int ff[n-1];
    int c,s,f;
    for(int i=0;i<n-1;i++)cin >> cc[i] >> ss[i] >> ff[i];

    for(int i=0;i<n-1;i++){
        t = 0;
        for(int j=i;j<n-1;j++){
        c = cc[j];
        s = ss[j];
        f = ff[j];
        if(t<s)t=s+c;
        else{
            t += c + (f-t%f)%f;
          }
       }
       cout << t << endl;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans, cand = 0, set()
    for i, j in enumerate(A, 1):
        i, j = min(i, j), max(i, j)
        if (i, j) in cand:
            ans += 1
        else:
            cand |= {(i, j)}
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 22500
N,M,X=map(int,input().split())
C=[];A=[]
for i in range(N):
    inp=list(map(int,input().split()))
    C.append(inp[0])
    A.append(inp[1:])
from itertools import product
ch=[0 for i in range(M)]
ans=10**10
ex=False
for it in list(product([True,False],repeat=N)):
    co=0
    for a in range(M):
        ch[a]=0
    for i in range(N):
        if it[i]:
            co+=C[i]
            for j in range(M):
                ch[j]+=A[i][j]
    ok=True
    for i in range(M):
        if ch[i]<X:
            ok=False
            break
    if ok:
        ans=min(ans,co)
        ex=True
if ex :
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9648
n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
s=0
t=0
p=10**9+7
for i in range(n):
    s=(s-(n-1-2*i)*x[i])%p
for i in range(m):
    t=(t-(m-1-2*i)*y[i])%p
print(s*t%p)


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Attack Survival
            var line = ReadLine();
            int N = line[0];
            int K = line[1];
            int Q = line[2];

            var A = new int[N + 1];

            for(int i = 0; i < Q; i++)
            {
                int a = int.Parse(Console.ReadLine());
                A[a]++;
            }

            for(int i = 1; i <= N; i++)
            {
                if (A[i] + K > Q)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 17728
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
#define MAX_N 100005
   
ull B=5575777;
ull mem[MAX_N];
   
ull pow(int x){
  if(x==0)return 1;
  if(mem[x]>0)return mem[x];
  if(x&1)return mem[x]=pow(x-1)*B;
  mem[x]=pow(x/2);
  mem[x]*=mem[x];
  return mem[x];
}
   
int n,q,l,r,t;
char s[MAX_N];
ull p[MAX_N];
   
ull get(int l,int r){
  return p[r]-p[l]*pow(r-l);
}
   
ull get(int l,int r,int x,char ch){
  ull res=p[r]-p[l]*pow(r-l);
  if(l<=x&&x<r){
    int dist=r-x-1;
    res-=pow(dist)*s[x];
    res+=pow(dist)*ch;
  }
  return res;
}
   
bool eq(int a,int b,int l,int r){
  return ( get(a,b) == get(l,r) );
}
   
bool eq(int a,int b,int l,int r, int x,char ch){
  return ( get(a,b,x,ch) == get(l,r,x,ch) );
}
   
bool calc(int a,int b,int l,int r){
  if(b-a!=r-l)return false;
  int L=0,R=b-a+1,M;
  while(R-L>1){
    M=(L+R)/2;
    if( eq(a,a+M,l,l+M) ){
      L=M;
    }else{
      R=M;
    }
  }
  if(L==b-a)return true;
  return ( eq(a,b,l,r, l+L, s[a+L]) || eq(a,b,l,r, a+L, s[l+L] )  );
}
   
   
bool solve(){
  int len=r-l;
  if(t==len)return true;
  if(t*2>=len){
    return calc(l,l+(len-t),r-(len-t),r);
  }
  if( calc(l,r-t,l+t,r) )return true;  
  return false;
}
   
int main(){
  scanf("%s",s);
  n=strlen(s);
   
  p[0]=0;
  for(int i=1;i<=n;i++){
    p[i]=p[i-1]*B+s[i-1];
  }
   
  scanf("%d",&q);
  while(q--){
    scanf("%d %d %d",&l,&r,&t);
   
    l--;
   
    if(solve())printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}

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

int main()
{
	int num,flag=0,bup=0,conp=0,cnt=0,anconp=0;
	char s[3][100];
	cin>>num;
	for(int i=0;i<3;i++)
		for(int n=0;n<num;n++)
			cin>>s[i][n];


		for(int n=0;n<num;n++)
		{
	
			if(s[0][n]==s[1][n] && s[1][n]==s[2][n])
			{
				conp=1;
			}
			else if(s[0][n]!=s[1][n] && s[1][n] ==s[2][n] && s[0][n]!=s[2][n])
			{
				bup=1;
				flag=0;
			}
			else if(s[0][n]!=s[1][n] && s[0][n] ==s[2][n] && s[1][n]!=s[2][n])
			{
				bup=0;
				flag=1;
			}
			else if(s[0][n]!=s[2][n] && s[1][n] ==s[0][n] && s[1][n]!=s[2][n])
			{
				bup=1;
				flag=2;
			}
			else
			{
				conp=1;
				anconp=1;
			}
			if(anconp==1)
			{
				s[1][n]=s[0][n];
				s[2][n]=s[0][n];
				cnt=cnt+2;
			}
			if(conp==0)
			{
				s[flag][n]=s[bup][n];
				cnt++;
			}

			conp=0,anconp=0;
		}

	cout<<cnt<<endl;


	
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
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; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string s;cin >> s;
    int K; cin >> K;
    vector<string> L;
    rep(i,s.size()){
        for(int j = 1;j <= 5;j++){
            if(i+j > s.size())break;
            L.push_back(s.substr(i,j));
        }
    }
    sort(all(L));
    int ct = 1;
    int ans = 0;
    rep(i,L.size()){
        if(K == ct){
            cout << L[ans] << endl;
            break;
        }
        else{
            if(L[i] == L[i+1]){
                ans++;
            }
            else{
                ct++;
                ans++;
            }
        }
    }
}

Measured memory_bytes: 1660
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

/*考えを書くスペース
xxxxxxxxxx  0000000000 最初のsearchで
xoooooooxx  0111111100
xxoooooxxx  0011111000
xxxoooxxxx  0001110000
xxxxoxxxxx  0000100000
xxxxxxxxxx  0000000000
xxxxoxxxxx  0000200000
xxxoooxxxx  0002220000
xxoooooxxx  0022222000
xxxxxxxxxx  0000000000
*/
//main.cpp----------------------------
#define max_h 50
#define max_w 50

void solve();
void search(int,int);

int h, w;
int c[max_h][max_w];

int main() {

  solve();

  return 0;
}

void solve() {

  while(1) {
    scanf("%d %d", &w, &h);
    if(w==0&&h==0) return;
    rep(i, h) {
      rep(j, w) {
        scanf("%d", &c[i][j]);
      }
    }

    int cnt = 0;
    rep(i, h) {
      rep(j, w) {
        if(c[i][j]==1) {
          search(i, j);
          cnt += 1;
        }
      }
    }

    cout << cnt << endl;
  }
}

void search(int x,int y) {

  if(x<0||x>=h||y<0||y>=w||c[x][y]==0)
    return;

  c[x][y] = 0;

  for(int dx=-1; dx<=1; ++dx) {
    for(int dy=-1; dy<=1; ++dy) {
      search(x+dx, y+dy);
    }
  }
}



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  string S;
  deque<char> dque;

  cin >> S;
  for (char c: S) {
    dque.push_back(c);
  }

  llong Q, idx, which;
  char c;
  int rev = 0;

  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    cin >> idx;
    if (idx == 1) {
      rev ^= 1;
    }
    else {
      cin >> which >> c;
      if (which == 1) {
        if (rev == 0) {
          dque.push_front(c);
        }
        else {
          dque.push_back(c);
        }
      }
      else {
        if (rev == 0) {
          dque.push_back(c);
        }
        else {
          dque.push_front(c);
        }

      }
    }
  }

  string ans = "";
  for (auto c: dque) {
    ans += c;
  }
  if (rev == 1) {
    reverse(ALL(ans));
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(3,vector<int>(N+1));
    vector<vector<int>> dp(3,vector<int>(N+1));
    for(int i=1;i<N+1;i++){
        cin >> A[1][i];
    }
    for(int i=1;i<N+1;i++){
        cin >> A[2][i];
    }
    for(int i=1;i<N+1;i++){
        dp[1][i]=dp[1][i-1]+A[1][i];
        dp[2][i]=max(dp[1][i],dp[2][i-1])+A[2][i];
    }
    cout << dp[2][N] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int h,w,a,b;
int M[10][10];
int S[10][10];
 
int main(){
	
	for ( int i = 1; i <= 3; i++ ){
		for ( int j = 1; j <= 3; j++ ){
			scanf("%d",&M[i][j]);
		}
	}
	scanf("%d",&a);
	for ( int i = 0; i < a; i++ ){
		scanf("%d",&b);
		for ( int r = 1; r <= 3; r++ ){
			for ( int c = 1; c <= 3; c++ ){
				if ( M[r][c] == b ){
					S[r][c] = true;
				}
			}
		}
	}
	
	int d1 = 0, d2 = 0, r1 = 0, r2 = 0, r3 = 0, c1 = 0, c2 = 0, c3 = 0;
	for ( int i = 1; i <= 3; i++ ){
		if ( S[i][i] ) d1++;
		if ( S[3-i+1][i] ) d2++;
		if ( S[1][i] ) r1++;
		if ( S[2][i] ) r2++;
		if ( S[3][i] ) r3++;
		if ( S[i][1] ) c1++;
		if ( S[i][2] ) c2++;
		if ( S[i][3] ) c3++;
	}
	if ( d1 == 3 || d2 == 3 || r1 == 3 || r2 == 3 || r3 == 3 || c1 == 3 || c2 == 3 || c3 == 3 ){
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

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

using namespace std;

typedef pair<int,int> ii;
int N,M,CNT = 1;

int main(){
  while(cin >> N >> M,N|M){
    vector<ii> phase;    
    int turn=0;
    phase.push_back(ii(0,N));
    while(true){
      turn++;
      int zero = 0,tmp[M+1],mex = 0;
      for(int i=0;i<=M;i++)tmp[i] = 0;
      for(int i=0;i<phase.size();i++){
	int key = phase[i].first;
	int value = phase[i].second;
	if(value&1)value--,tmp[key]++;
	if(value / 2)mex = max(mex,key+1);
	tmp[key+1] += value / 2, tmp[0] += value / 2;
      }
      phase.clear();
      for(int i=0;i<=M;i++)if(tmp[i] != 0)phase.push_back(ii(i,tmp[i]));
      if(mex == M){
	cout << "Case " << CNT++ << ": " << turn << endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		boolean[][] t = new boolean[4][13];
	
		for(int i = 0; i < n; i++) {
			char egara = scan.next().charAt(0);
			int number = scan.nextInt();
			
			switch(egara) {
			case 'S':
				t[0][number-1] = true;
				break;
			case 'H':
				t[1][number-1] = true;
				break;
			case 'C':
				t[2][number-1] = true;
				break;
			case 'D':
				t[3][number-1] = true;
				break;
			}
		}

		char[] check = {'S', 'H', 'C', 'D'};
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 13; j++) {
				if(!t[i][j]) {
					System.out.println(check[i] + " " + (j + 1));
				}
			}
		}
		
		
	}

}



Measured memory_bytes: 26476
from sys import stdin
import queue

# ??£??\?????????
adjacent =(
    (1,3),     # 0
    (0,2,4),   # 1
    (1,5),     # 2
    (0,4,6),   # 3
    (1,3,5,7), # 4
    (2,4,8),   # 5
    (3,7),     # 6
    (4,6,8),   # 7
    (5,7)      # 8
)

# ?±???¢?????????
class State:
    def __init__(self,board,space,prev):
        self.board = board # ?????¢?????¨?????????
        self.space = space # ?????´????????????(0?????????)
        self.prev = prev   # 1??????????±???¢(State??????????????§??????)

def bf_search(start,end):
    q = queue.Queue()
    q.put(State(start,start.index(0),None)) #item???Q?????\??????
    table = {} # ??????????????????
    table[tuple(start)] = True # ???????±???¢????????§???????????????????????????

    while not q.empty(): # empty()???Q???????????´??????True????????????????????§????????´??????False?????????
        a = q.get() # Q??????item????????????????????????????????????
        for i in adjacent[a.space]: # i????????????0?????????
            b = a.board[:] # ???????????¢???b????????????
            b[a.space] = b[i] # ?¬?????????¢?????????
            b[i] = 0          # ?¬?????????¢?????????
            
            
            key = tuple(b) # b???????????¨??????table????????¨??????????¢??????????
            if key in table:
                continue # ?????¨?????????for?????????????????£?????°???????????¢b?????????

            # table????????¨???????????´????????°???????±???¢c?????????
            # b?????°???????????¢?????¨????????????i????????????0????????????a???1??????????±???¢
            c = State(b,i,a) 

            # b???end????????´?????????printAns()??§???????????°?????¨???
            if b == end:
                return printAns(c)

            # ?????´???????????£??????Q???c????????????
            q.put(c)
            # key????????£???True?????????
            table[key] = True

count = -1
def printAns(c):
    global count
    if c is not None: 
        count += 1
        printAns(c.prev) # c.prev??????????????????????????¨????????£????????°?????°??????
    return count


# ??????????????????????????????
end = [1,2,3,4,5,6,7,8,0]

# ??\???
start = [ int(n) for _ in range(3) for n in stdin.readline().split() ]

if start == end:
    print(0)
else:
    print(bf_search(start,end))

Measured memory_bytes: 77968
#include <iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{	
	long long n, i, a[110], res = 0;
	double m,sum=0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	
	m = round(sum / n);
	for (i = 0; i < n; i++) {
		res += pow((a[i] - m), 2);
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import math
mod = 10 ** 9 + 7
n = int(input())
list = [0] * (n + 1)

#素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a, b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2]!=1:
        q = r[2] // w[2]
        r2 = w
        w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0], w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a, m)[0]
    return (m + x % m) % m

for x in range(n - 1):
    facList = factorization(x + 2)
    for fac in facList:
        list[fac[0]] += fac[1]
ans = 1
for x in list:
    ans *= x + 1
    ans %= mod
print(ans)

Measured memory_bytes: 3188
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let sum lst = List.fold_left (fun acc s -> acc +. s) 0. lst

let sd n lst =
  let n = float_of_int n in
  let m = sum lst /. n in
  sqrt (sum (List.map (fun s -> (s -. m)*.(s -. m)) lst) /. n)

let () =
  let rec doit () =
    match read_int () with
    | 0 -> ()
    | n -> begin
        let l = read_line () in
        let lst = List.map float_of_string (split l ' ') in
        Printf.printf "%f\n" (sd n lst);
        doit ();
      end
  in
  doit ()

Measured memory_bytes: 5592
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = input()

    def judge():
        if "C" in S:
            idx = S.index("C")
            for char in S[idx:]:
                if char == "F":
                    return True
        return False

    print("Yes" if judge() else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61908
c=[0,2,5,5,4,5,6,3,7,6]
N,M=gets.split.map &:to_i
a=gets.split.map &:to_i
d=Array.new(N+1,p)
d[0]=0
0.upto(N){|i|q=[];M.times{|m|c[a[m]]<=i&&d[i-c[a[m]]]&&q<< d[i-c[a[m]]]*10+a[m]};q.size>0&&d[i]=q.max}
p d[N]

Measured memory_bytes: 36860