akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

int vec[12][13];
int mi=1000000000;
int n,m,x;

void dfs(vector<int> A,int n){
  if((int)A.size()==n){
    vector<int> B(m+1,0);
    bool b=true;
    rep(i,n){
      if(A[i]==1){
        rep(j,m+1){
          B[j]+=vec[i][j];
        }
      }
    }
    for(int j=1;j<=m;j++){
      if(B[j]<x) b=false;
    }
    if(b) chmin(mi,B[0]);
   
    return;  
  }
  
  rep(i,2){
    A.push_back(i);
    dfs(A,n);
    A.pop_back();
  }
}

int main() {
  cin>>n>>m>>x;
  
  rep(i,n){
    rep(j,m+1){
      cin>>vec[i][j];
    }
  }
  
  vector<int> A={};
  dfs(A,n);
  
  if(mi<1000000000) cout<<mi<<endl;
  else cout<<-1<<endl;

  return 0;
}

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

int main(){
    int k;
    string s;
    cin >> k;
    cin >> s;
    if(k >= s.size()){
        cout << s << endl;
    }
    else{
        for(int i = 0; i < k; i++){
            printf("%c", s[i]);
        }
        printf("...\n");
    }

    return 0;
}

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

int S[100000 + 1],n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  while(left < right) {
    int mid = (left + right) / 2;
    if(S[mid] == key) return 1;
    else if(S[mid] < key) left = mid + 1;
    else right = mid;
  }
  return 0;
}

int main() {
 
  cin >> n;

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

  int q;
  cin >> q;
  int key,ans = 0;

  for(int i = 0; i < q; i++) {
    cin >> key;
    if(binarySearch(key)) ans++;
  }

  cout << ans << endl;


}


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

const ll INF = 1LL << 60;

ll H, W, K;
vector<string> s;

int c[10][1010];

int main() {
    cin >> H >> W >> K;
    s.resize(H);

    rep(i, H) {
        cin >> s[i];
    }

    ll ans = INF;
    for (int i = 0; i < 1 << (H - 1); i++) {
        vector<ll> lines;
        lines.push_back(0);
        for (int j = 0; j < (H - 1); j++) {
            if (i >> j & 1) {
                lines.push_back(j + 1);
            }
        }
        lines.push_back(H);

        // if (i == 1) {
        //     rep(k, lines.size()) cout << lines[k] << " ";
        // }
        // cout << endl;
        // どの行がどのグループか
        // 行 -> グループを求める
        vector<ll> id(H, -1);
        ll group_num = 0;
        for (int j = 0; j < lines.size() - 1; j++) {
            int diff = lines[j + 1] - lines[j];
            for (int k = 0; k < diff; k++) {
                // groups[group_num].push_back(lines[j] + k);
                id[lines[j] + k] = group_num;
            }
            group_num++;
        }

        rep(j, H)rep(k, W) c[j][k] = 0;
        rep(j, H)rep(k, W) c[id[j]][k] += (s[j][k] - '0');

        // debug
        // cout << "--- " << i << " ---" << endl;
        // rep(j, H) {
        //     cout << id[j] << " ";
        // }
        // cout << endl;
        // rep(j, group_num) {
        //     rep(k, W) {
        //         cout << c[j][k] << " ";
        //     }
        //     cout << endl;
        // }
        vector<ll> now(group_num, 0);

        auto add = [&](int j) {
            rep(i, group_num) now[i] += c[i][j];
            rep(i, group_num) if (now[i] > K) return false;

            return true;
        };
        ll tmp_ans = group_num - 1;

        for (int j = 0; j < W; j++) {
            if (!add(j)) {
                tmp_ans++;
                now = vector<ll>(group_num, 0);

                if (!add(j)) {
                    tmp_ans = INF; 
                    break;
                }
            }
        }

        ans = min(ans, tmp_ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3660
#17:37
n = int(input())
can = []
for _ in range(n):
  raw = input()
  made = []
  for k in range(10):
    made.append(ord(raw[k])-97)
  made.sort()
  can.append(made)
can.sort()
ans = 0
combo = 0
for i in range(1,n):
  if can[i-1] == can[i]:
    combo += 1
  else:
    combo = 0
  ans += combo
print(ans)

Measured memory_bytes: 24624
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int x, n;
	cin >> x >> n;
	vector<int>a(101);
	rep(i, n) {
		int k;
		cin >> k;
		a[k]++;
	}
	//cout << 1;
	rep(i, 100) {
		if (x - i >= 0) {
			if (a[x - i] == 0) {
				cout << x - i;
				return 0;
			}
		}
		if (x + i <= 101) {
			if ( a[x + i] == 0) {
				cout << x + i;
				return 0;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int len = s.length();
  char o1[len], o2[len];
  int ans1 = 0, ans2 = 0;
  for(int i = 0; i < len; i++){
    if(i%2){
      o1[i] = '1';
      o2[i] = '0';
    }
    else{
      o1[i] = '0';
      o2[i] = '1';
    }
  }
  for(int i = 0; i < len; i++){
    if(s[i] != o1[i])ans1++;
    else if(s[i] != o2[i])ans2++;
  }
  cout << min(ans1, ans2);
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

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

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    string ans = "";
    for(char c: s){
    	if(ans[ans.length()-1] != c){
    		ans += c;
    	}
    }    
    cout<<ans.length()<<endl;
    return 0;
}





Measured memory_bytes: 592
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define readint ({int t;cin >> t;t;})

const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class CDivideTheProblems {
public:
    int D[101010];
void solve(std::istream& cin, std::ostream& cout) {
    int N;
    cin >> N;
    _for(i,N)cin >> D[i];
    sort(D, D+N);
    cout << D[N/2] - D[N/2 - 1] << endl;


}
};


#undef int
int main() {
	CDivideTheProblems solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(0); ios::sync_with_stdio(0); out<<fixed<<setprecision(20);
	solver.solve(in, out);
	return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>x(m);
  for(int i=0;i<m;i++){
    cin>>x[i];
  }
  sort(x.begin(),x.end());
  vector<int>d(m);
  for(int i=0;i<m-1;i++){
    d[i]=x[i+1]-x[i];
  }
  sort(d.begin(),d.end());
  for(int i=0;i<n-1;i++){
    d.pop_back();
  }
  int num=0;
  for(int i=0;i<m-n+1;i++){
    num+=d[i];
  }
  cout<<num<<endl;
}
  

Measured memory_bytes: 1024
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    Edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        Edge[a-1].append((b-1, c))
        Edge[b-1].append((a-1, c))
    Q, K = map(int, input().split())
    q = deque()
    Dist = [-1] * N
    q.append((K-1, K-1, 0))
    while q:
        nowN, preN, nD = q.popleft()
        if Dist[nowN] == -1:
            Dist[nowN] = nD
            for e, add in Edge[nowN]:
                if e != preN: q.append((e, nowN, nD + add))
    Ans = [None] * Q
    for i in range(Q):
        x, y = map(int, input().split())
        Ans[i] = str(Dist[x-1] + Dist[y-1])
    print("\n".join(Ans))

    return 0

if __name__ == "__main__":
    solve()

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

int main(){
 int X,N;
 cin>>X>>N;
 vector<int>p(N),q(300);
 for(int i=0;i<N;i++){
   cin>>p[i];
 }

 for(int i=0;i<300;i++){
   q[i]=i;
   for(int j=0;j<N;j++){
    if(p[j]==q[i]){
     q[i]=1111111;
     break;
    }
   }
 }
 
 int ans=11111111;
 for(int i=0;i<300;i++){
   ans=min(ans,abs(q[i]-X));
 }

   
   for(int i=0;i<300;i++){
     if(ans==abs(q[i]-X)){
       cout<<i<<endl;
       break;
    }
   }  
      
 }
 

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

int main(){
	int a, b;
	function<int(int, int)>gcd = [&](int a, int b) {if (!b)return a; return gcd(b, a%b); };
	while (cin >> a >> b)cout << gcd(a, b) << endl;
	return 0;
}

Measured memory_bytes: 3004
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int Maxn = 100000;
const int Mod = 1000000000 + 7;
int n,a[1010],minn,cnt;
int main()
{
    cin>>n;
    minn = Mod;
    for (int i = 0; i < n; i++)
        cin>>a[i];
    for (int i = 0; i < n; i++)
    {
        cnt = 0;
        while(a[i] % 2 == 0)
        {
            cnt++;
            a[i]/=2;
        }
        minn = min(minn,cnt);
    }
    cout<<minn<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

int main(){
  int x,n,p,a=1000,f,d;
  cin >> x >> n;
  vi s(n);
  vi ans;

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

  if(n==0){
    cout << x << endl;
    return 0;
  }

  for(int i=-110; i<=110; i++){
    bool t = true;
     rep(j,n){
       if(i==s[j])t=false;
     }
    if(t){
      a = min(a,abs(x-i));
    }
  }

  f=x-a;
  d=x+a;
  rep(i,n){
    if(f==s[i])f=1000;
    if(d==s[i])d=1000; 
  }
  a=min(f,d);

  cout << a << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX (int)1e+5
#define INF 1e+9
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg
#define newl cout<<"\n"
using namespace std;
typedef long long ll;
int N,K;
ll x[NMAX];
int main(){
  scan(N);scan(K);
  scan(x[0]);
  int cen;
  if(x[0]<0) cen=N;
  else cen=0;
  rep1(i,N-1){
    scan(x[i]);
    if(x[i]==0) cen=i;
    if(x[i]*x[i-1]<0) cen=i;
  }
  ll res=INF,j=0;
  if(cen-K>=0) res=abs(x[cen-K]);
  else while(cen-K+j+1<0) j++;
  for(int i=j;i<K-1;i++){
    if(cen+i>=N) break;
    ll d=min(abs(x[cen+i])*2+abs(x[cen-K+i+1]),abs(x[cen+i])+abs(x[cen-K+i+1])*2);
    //      prin(d);newl;
    res=min(d,res);
  }
  if(cen+K-1<N) res=min(res,x[cen+K-1]);
  prin(res);newl;
  
  return 0;
}


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

int main() {
  int a, b, k;
  cin >> k >> a >> b;
  bool ok = false;
  for(int i=a;i<=b;i++) {
    if(i % k == 0) {
      ok = true;
      break;
    }
  }
  if(ok) cout << "OK" << endl;
  else cout << "NG" << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int n;

	std::cin >> n;

	std::vector<int> d(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> d[i];
	}

	long long sum = 0;
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = i + 1; j < n; j++)
		{
			sum += d[i] * d[j];
		}
	}

	std::cout << sum << std::endl;

	return 0;
}

Measured memory_bytes: 256
import math

NK = input().split();
N,K = int(NK[0]),int(NK[1]);
min = N;

#桁が大きい時の処理
if(K == 1):
    while(int(len(str(N))) > 2):
        N = int(N - K * (N / 2));
else:
    border = math.floor(N / K);
    N = N - K * border;
        
flag = True;
while flag == True:
    N = abs(N - K);
    if(N <= min):
        min = N;
    else:
        flag = False;
    
print(min);

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
#define allchar(c) for(char c='a';c<='z';c++)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef queue<int> qi;

const int mod=1e9+7;

ll modpow(ll a,ll b,ll p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    S s;
    cin >> s;
    vc t(s.size());
    rp(i,t.size()){
        t.at(i)=s.at(i);
    }
    ll ans=0,p=0;
    llrp(i,s.size()){
        if(s.at(i)=='W'){
            ans+=i-p;
            p++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 788
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;

struct Edge {
  long long to;
  long long cost;
};
using Graph = vector<vector<p>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;


/* dijkstra(G,s,dis,prev)
   入力：グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
   計算量：O(|E|log|V|)
   副作用：dis, prevが書き換えられる
   */
void dijkstra(const Graph &G, int s, vector<long long> &dis, vector<int> &prev) {
  int N = G.size();
  dis.resize(N, INF);
  prev.resize(N, -1); // 初期化
  priority_queue<P, vector<P>, greater<P>> pq;
  dis[s] = 0;
  pq.emplace(dis[s], s);
  while (!pq.empty()) {
    P p = pq.top();
    pq.pop();
    int v = p.second;
    if (dis[v] < p.first) {
      continue;
    }
    for (auto &e : G[v]) {
      if (dis[e.first] > dis[v] + e.second) {
        dis[e.first] = dis[v] + e.second;
        prev[e.first] = v; // 頂点 v を通って e.to にたどり着いた
        pq.emplace(dis[e.first], e.first);
      }
    }
  }
}
/* get_path(prev, t)
   入力：dijkstra で得た prev, ゴール t
   出力： t への最短路のパス
   */
vector<int> get_path(const vector<int> &prev, int t) {
  vector<int> path;
  for (int cur = t; cur != -1; cur = prev[cur]) {
    path.push_back(cur);
  }
  reverse(path.begin(), path.end()); // 逆順なのでひっくり返す
  return path;
}
int h, w, ch, cw, dh, dw;

ll f(int y, int x) {
  return y*w + x;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;cw--;dh--;dw--;
  vector<string> v(h);
  rep(i, h) cin >> v[i];
  Graph g(h*w);
  rep(i, h) rep(j, w){
    if(v[i][j] == '#') continue;
    for (int k1 = -2; k1 <= 2; k1++) {
      for (int k2 = -2; k2 <= 2; k2++) {
        if(k1 == 0 && k2 == 0) continue;
        int ny = i+k1;
        int nx = j+k2;
        if(ny >= h || nx >= w || ny < 0 || nx < 0) continue;
        if(v[ny][nx] == '#') continue;
        // cout << i << ' ' << j  << ' ' << k1 << ' ' << k2 << endl;
        // cout << f(i, j) << ' ' << f(ny, nx) << endl;
        if((k1==1&&k2==0) || (k1==-1&&k2==0) || (k1==0&&k2==1) || (k1==0&&k2==-1)){
          g[f(i, j)].push_back({f(ny, nx), 0});
        }else{
          g[f(i, j)].push_back({f(ny, nx), 1});
        }
      }
    }
  }

  vector<ll> dist;
  vector<int> prev;

  // dijkstra(g, f(0, 0), dist, prev);
  dijkstra(g, f(ch, cw), dist, prev);

  ll res = dist[f(dh, dw)];
  if(res == INF) cout << -1 << endl;
  else cout << res << endl;
}


Measured memory_bytes: 171636
#include <bits/stdc++.h>
using namespace std;
int main(){
double a,b,c,h;
cin>>a>>b>>c;
h=b*sin(M_PI*c/180);
printf("%f\n%f\n%f\n",a*h/2,a+b+sqrt(( a-(b*cos(M_PI*c/180)) )*( a-(b*cos(M_PI*c/180)) )+h*h),h);
return 0;
}

Measured memory_bytes: 3464
/*
*
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#define CLR(ARR,NUM) memset(ARR,NUM,sizeof(ARR))
#define GETNUM(NUM) scanf("%d",&NUM)
#define faster_io() ios_base::sync_with_stdio(false)
using namespace std;
const int MAXN = 20;
int a[MAXN];
bool vaild;
void dfs(int x,int l,int r)
{
	if(x==10){
		vaild=true;
		return;
	}
	if(a[x]>l){
		dfs(x+1,a[x],r);
	}
	if(a[x]>r){
		dfs(x+1,l,a[x]);
	}
}

int main()
{
	int n;
	cin >> n;
	while(n--){
		for(int i=0;i<10;i++){
			GETNUM(a[i]);
		}
		vaild=false;
		dfs(0,0,0);
		if(vaild){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
struct edge
{
    ll to;
    ll cost;
};
typedef pair<ll, ll> P;
vector<vector<edge>> G;
vector<ll> dijkstra(ll s, ll N)
{
    vector<ll> value(N, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    value[s] = 0;
    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (value[v] < p.first)
        {
            continue;
        }
        rep(i, G[v].size())
        {
            edge e = G[v][i];
            if (value[e.to] > value[v] + e.cost)
            {
                value[e.to] = value[v] + e.cost;
                que.push(P(value[e.to], e.to));
            }
        }
    }

    return value;
}
int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;

    G = vector<vector<edge>>(N);

    rep(i, N - 1) {
        G[i].push_back({i + 1, 1});
        G[i + 1].push_back({i, 1});
    }
    G[X - 1].push_back({Y - 1, 1});
    G[Y - 1].push_back({X - 1, 1});

    vector<ll> d(N), ans(N - 1, 0);
    d = dijkstra(X - 1, N);

    rep(i, N) {
        repd(j, i + 1, N) {
            int v = min(j - i, d[i] + d[j]);
            ans[v - 1]++;
        }
    }

    rep(i, ans.size()) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 384
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

int main(){
  ll N;
  cin >> N;
  vector<vector<ll>> c(2010,vector<ll> (2010,1));
  for(int i = 2;i <= 2000;i++){
    for(int j = 1;j < i;j++){
      c[i][j] = c[i-1][j] + c[i-1][j-1];
      c[i][j] %= MOD;
    }
  }

  ll ans = 0;

  for(int i = 1;3*i <= N;i++){
    ans += c[(N-3*i)+(i-1)][i-1];
    ans %= MOD;
  }

  cout << ans << endl;




  return 0;
}


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

int main(){
  
  int N,K ;
  cin >> N >> K;
  
  long long int A[200001];
  for(int i=0 ; i<N ; ++i) cin >> A[i];
  
  for(int i=K ; i<N; ++i){
    if(A[i]>A[i-K]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
}


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

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

  vector<int> p(N);
  vector<int> sortP(N);

  for (int i = 0; i < N; i++)
  {
    cin >> p.at(i);
  }

  sortP = p;

  sort(sortP.begin(), sortP.end());

  int invalidCount = 0;

  for (int i = 0; i < N; i++)
  {
    if (p.at(i) != sortP.at(i))
      invalidCount++;
  }

  cout << (invalidCount > 2 ? "NO" : "YES") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	int m=0;
	int id=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(abs(m)<abs(a[i])){
			id=i;
			m=a[i];
		}
	}
	cout << 2*n-1 << endl;
	for(int i=0;i<n;i++){
		cout << id+1 << " " << i+1 << endl;
	}
	if(m>0){
		for(int i=0;i<n-1;i++){
			cout << i+1 << " " << i+2 << endl;
		}
	}
	else{
		for(int i=0;i<n-1;i++){
			cout << n-i << " " << n-1-i << endl;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int t[2],a[2],b[2];
    for(int i=0;i<2;i++)cin >> t[i];
    for(int i=0;i<2;i++)cin >> a[i];
    for(int i=0;i<2;i++)cin >> b[i];
    long long int move=t[0]*(a[0]-b[0])+t[1]*(a[1]-b[1]);
    long long int MAX=max(max(0LL,t[0]*(a[0]-b[0])),move);
    long long int MIN=min(min(0LL,t[0]*(a[0]-b[0])),move);
    if(move==0)cout << "infinity";
    else{
        if(MIN==0 || MAX==0)cout << 0;
        else if(move>0 && (abs(MIN)%move)!=0)cout << 2*(abs(MIN)/move+1) - 1;
        else if(move>0 && (abs(MIN)%move)==0)cout << 2*(abs(MIN)/move+1) - 2;
        else if(move<0 && (MAX%abs(move))!=0)cout << 2*(MAX/abs(move)+1) - 1;
        else if(move<0 && (MAX%abs(move))==0)cout << 2*(MAX/abs(move)+1) - 2;
    }
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += v[i]-i-1;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3416
#include<stdio.h>
#define MAX 101

int matrixChainOrder(int *);
int min(int , int );

int n;

int main()
{
  int i, r, c, p[MAX];

  scanf("%d", &n);
  for(i=1; i<=n; i++)
    {
      scanf("%d %d", &r, &c);
      if(i==1)
	{
	  p[i-1] = r;
	  p[i] = c;
	}
      else p[i] = c;
    }

  printf("%d\n", matrixChainOrder(p));

  return 0;
}

int matrixChainOrder(int *p)
{
  int i, j, k, m[MAX][MAX], l;

  for(i=1; i<=n; i++) m[i][i] = 0;
  for(l=2; l<=n; l++)
    {
      for(i=1; i<=n - l + 1; i++)
	{
	  j = i + l - 1;
	  m[i][j] = 1 << 21;
	  for(k=i; k<=j-1; k++)
	    {
	      //printf("%d %d %d\n", p[i - 1], p[k], p[j]);
	      m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i - 1] * p[k] * p[j]);
	    }
	}
    }
  
  return m[1][n];
}

int min(int a, int b)
{
  if(a <= b) return a;
  else return b;
}

Measured memory_bytes: 632
# じょえチャンネルおもしろいよ～～～
# https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if i%2==0 and a[i]%2==1:ans+=1
print(ans)

Measured memory_bytes: 9100
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,C;
    cin >> N >> C;
    int D[C][C], Color[N][N];
    rep(i,0,C)rep(j,0,C)cin >> D[i][j];
    rep(i,0,N)rep(j,0,N){
        cin >> Color[i][j];
        Color[i][j]--;
    }
    int dif[3][C];
    rep(i,0,3)rep(j,0,C)dif[i][j] = 0;
    rep(i,0,N)rep(j,0,N){
        rep(k,0,C){
            dif[(i + j) % 3][k] += D[ Color[i][j] ][k];
        }
    }
    int mini = INF;
    rep(i,0,C)rep(j,0,C)rep(k,0,C){
        if(i == j || i == k || j == k)continue;
        mini = min(mini, dif[0][i] + dif[1][j] + dif[2][k]);
    }
    cout << mini << endl;
}

Measured memory_bytes: 1280
from collections import deque

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

reversing = False

for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        reversing = not reversing
    else:
        if query[1] == '1':
            if not reversing:
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if reversing:
                S.appendleft(query[2])
            else:
                S.append(query[2])

print(''.join(S)) if not reversing else print(''.join(reversed(S)))

Measured memory_bytes: 8436
n = int(input())
s = input()
left_w = 0
right_e = s.count('E')
ans = left_w + right_e
for c in s:
    if c == 'E':
        right_e -= 1
    ans = min(ans, left_w + right_e)
    if c == 'W':
        left_w += 1
print(ans)

Measured memory_bytes: 3700
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, D = il()
    print(math.ceil(N/((D*2)+1)))


if __name__ == '__main__':
    main()


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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    cout << (n + 1) / 2;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair <int, int>
#define xx first
#define yy second
#define LL long long
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
 
const int N = 100100, M = 400100;
char s[M];
int nx[M * 2][26], cnt[M * 2], rt, pos[N], is[M * 2], res[N], tot;
 
struct data {
    string s;
    int id;
    data () {}
    data (string s, int id) : s (s), id (id) {}
};
 
vector <data> g[M];
 
int newnode () {
    memset (nx[tot], -1, sizeof nx[tot]);
    cnt[tot] = 0;
    is[tot] = 0;
    return tot++;
}
 
void init () {
    tot = 0;
    rt = newnode ();
}
 
int ins () {
    int now = rt;
    for (int i = 0; s[i]; i++) {
        s[i] -= 'a';
//        cout << (int)s[i];
        if (nx[now][s[i]] == -1) {
            nx[now][s[i]] = newnode ();
        }
        now = nx[now][s[i]];
        cnt[now]++;
//        cout << now << endl;
    }
//    cout << endl;
    is[now]++;
    return now;
}
 
int sum[28][28], summ;
 
void dfs (int now) {
//    cout << now << endl;
    for (int i = 0; i < g[now].size(); i++) {
        int &ans = res[g[now][i].id];
        ans = 1;
        string s = g[now][i].s;
//        cout << g[now][i].id << ' ' << s << endl;
        for (int j = 0; j < 26; j++) {
            for (int k = 0; k < j; k++) {
                ans += sum[s[j] - 'a'][s[k] - 'a'];
            }
        }
        ans += summ;
    }
    for (int i = 0; i < 26; i++) if (nx[now][i] != -1) {
        for (int j = 0; j < 26; j++) if (nx[now][j] != -1 && i != j){
//            cout << i << ' ' << j << ' ' << cnt[nx[now][j]] << endl;
            sum[i][j] += cnt[nx[now][j]];
        }
        if (is[now]) summ++;
        dfs (nx[now][i]);
        for (int j = 0; j < 26; j++) if (nx[now][j] != -1 && i != j){
            sum[i][j] -= cnt[nx[now][j]];
        }
        if (is[now]) summ--;
    }
    return;
}
 
int main ()
{
//    freopen ("in", "r", stdin);
//    ios::
    init ();
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        scanf ("%s", s);
        pos[i] = ins ();
    }
    int q, k;
//    return 0;
    cin >> q;
    for (int i = 1; i <= q; i++) {
        scanf ("%d%s", &k, s);
        g[pos[k]].push_back (data (s, i));
    }
    dfs (rt);
    for (int i = 1; i <= q; i++) {
        printf ("%d\n", res[i]);
    }
//    cout << res << endl;
}

Measured memory_bytes: 112112
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  int a, b, c; cin >> a >> b >> c;
  if((a*100+b*10+c)%4 == 0){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
  system("pause");
}

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

class Program
{
    static void Main(string[] args)
    {
        var input1 = Console.ReadLine().Split(' ');
        var enemyNum = int.Parse(input1[0]);
        var killNum = int.Parse(input1[1]);
        var input = Console.ReadLine().Split(' ');

        if(killNum >= enemyNum)
        {
            Console.WriteLine(0);
            return;
        }

        var enemyHp = new List<long>();
        long ans = 0;
        foreach (var n in input) 
        {
            enemyHp.Add(long.Parse(n));
        }

        enemyHp.Sort();
        for(var i = 0; i < (enemyNum - killNum); i++)
        {
            ans += enemyHp[i];
        }

        Console.WriteLine(ans);
        Console.ReadLine();
        return;
    }
}



Measured memory_bytes: 33792
n,k = map(int,input().split())
x = list(map(int,input().split()))

score = []
for i in range(n-k+1):
    l = abs(x[i]) + (x[i+k-1] - x[i])
    r = abs(x[i+k-1]) + (x[i+k-1] - x[i])
    score.append(l)
    score.append(r)
score.sort()
print(score[0])

Measured memory_bytes: 14384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

struct UnionFind {
  vector<ll> p;
  vector<ll> sz;
  
  UnionFind(ll n) : p(n), sz(n,1LL) {
    for(ll i=0; i<n; i++)
      p.at(i) = i;
  }
  
  ll root(ll x) {
    if(p.at(x) == x)
      return x;
    return p.at(x) = root(p.at(x));
  }
  
  void unite(ll x, ll y) {
    ll rx=root(x), ry=root(y);
    if(rx == ry)
      return;
    if(sz.at(rx) < sz.at(ry))
      swap(rx,ry);
    sz.at(rx) += sz.at(ry);
    p.at(ry) = rx;
  }
  
  ll size(ll x) {
    return sz.at(root(x));
  }
};

int main() {
  ll N,M,i,A,B,nd1,nd2;
  cin >> N >> M;
  vector<pair<ll, ll>> g(M);
  vector<ll> as(M);
  as.at(M-1) = N*(N-1)/2;
  
  for(i=0; i<M; i++) {
    cin >> A >> B;
    g.at(i).first = A;
    g.at(i).second = B;
  }
  
  UnionFind uf(N);
  
  for(i=M-2; i>=0; i--) {
    nd1 = g.at(i+1).first-1;
    nd2 = g.at(i+1).second-1;
    if(uf.root(nd1) == uf.root(nd2)) 
      as.at(i) = as.at(i+1);
    else {
      as.at(i) = as.at(i+1)-uf.size(nd1)*uf.size(nd2);
      uf.unite(nd1, nd2);
    }
  }
  
  REP(i,M)
    cout << as.at(i) << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> V(n);
    vector<int> C(n);
    for(int i=0; i<n; i++){
        cin >> V[i];
    }
    for(int i=0; i<n; i++){
        cin >> C[i];
    }
    int ans=0;
    for(int i=0; i<n; i++){
        if(V[i]-C[i]<=0){
            continue;
        }
        ans += V[i]-C[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'

#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int x[5];
    int ans;
    forn(i,5){
        cin>>x[i];
        if(!x[i])ans=i+1;
    }
    cout<<ans;

    
    
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	string S[3];
	FOR(i, 0, 3) cin >> S[i];

	char ans;
	char t = 'a';
	while (true) {
		if (t == 'a') {
			if (S[0].size() == 0) {
				ans = 'A';
				break;
			}
			t = S[0][0];
			S[0].erase(0,1);
		}
		else if (t == 'b') {
			if (S[1].size() == 0) {
				ans = 'B';
				break;
			}
			t = S[1][0];
			S[1].erase(0,1);
		}
		else {
			if (S[2].size() == 0) {
				ans = 'C';
				break;
			}
			t = S[2][0];
			S[2].erase(0,1);
		}
	}

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


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
    cin >> data.at(i).at(j);
    }
  }
  
  int x =0; //answerの列の個数
  for (int i = 0; i < W; i++) {
    bool flag = false;
    for (int j = 0; j < H; j++) {
      if (data.at(j).at(i) == '#') {
        x++;
        flag = true;
        break;
      }
    }
    if (flag == false) {
        for (int k = 0; k < H; k++) {
          data.at(k).at(i) = '-';
        }
    }
  }
  
  int y=0;//answerの行の個数
  for (int i = 0; i < H; i++) {
    bool flag = false;
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) == '#') {
        y++;
        flag = true;
        break;
      }  
    }
    if (flag == false) {
        for (int k = 0; k < W; k++) {
          data.at(i).at(k) = '-';
        }
    }
  }
  vector<char> henkan = {};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) != '-') {
        henkan.push_back(data.at(i).at(j));
      }
    }
  }
  
  vector<vector<char>> answer(y, vector<char>(x));
  for (int i=0; i < y; i++) {
    for (int j = 0; j < x; j++) {
      data.at(i).at(j) = henkan.at(i*x+j);
      cout << data.at(i).at(j);
      if (j == (x-1)) {
        cout << endl; // 末尾なら改行
      } 
    }
  }

  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
using ll = long long;
using ull = unsigned long long;

vector<int> v;

int main() {
    FAST;

    int n;
    cin >> n;

    rep(i, n){
        int x;
        cin >> x;
        v.push_back(x);
    }

    int min = (1 << 30);
    rep(i, 100){
        int P = i + 1;
        int sum = 0;
        rep(j, size(v)){
            int d = (v[j] - P);
            sum += d * d;
        }
        min = std::min(min, sum);
    }

    println(min);
}

Measured memory_bytes: 256
s=input()
even=["L","U","D"] #mondaide
odd=["R","U","D"]
l=len(s)
fumiyasui=False
for i in range(l):
  if i%2==0:
    if s[i] in odd:
      fumiyasui=True      
    else:
      print("No")
      exit()
  else:
    if s[i] in even:
      fumiyasui=True      
    else:
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 3064
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i32 = input();
    println!("{}", n * (n + 1) / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
const ld pi=3.141592653589793238;

const ll N=5e5+5;
ll arr[N],lastOcc[N],n,q,x[N];
vll st[4*N];


/* builds in O(nlogn)  */
void build(ll l=1,ll r=n,ll pos=1)
{
  if(l==r)
  {
    st[pos].pb(x[l]);
    return;
  }

  ll mid=(l+r)>>1,lc=pos<<1,rc=lc^1;
  build(l,mid,lc);
  build(mid+1,r,rc);
  ll j=0,z=0;
  while(j<sz(st[lc]) || z<sz(st[rc]))
  {
    if(j<sz(st[lc]) && z<sz(st[rc]))
    {
      if(st[lc][j]<=st[rc][z]) st[pos].pb(st[lc][j]),j++;
      else st[pos].pb(st[rc][z]),z++;
    }
    else if(j<sz(st[lc])) st[pos].pb(st[lc][j]),j++;
    else st[pos].pb(st[rc][z]),z++;
  }

}

ll qry(ll ql,ll qr,ll x,ll l=1,ll r=n,ll pos=1)
{
  if(ql>r || qr<l) return 0;

  if(ql<=l && qr>=r) 
  {
    ll idx=lower_bound(ALL(st[pos]),x)-st[pos].begin();
    return idx;
  }
  
  ll mid=(l+r)>>1,lc=pos<<1,rc=lc^1;
  return qry(ql,qr,x,l,mid,lc)+qry(ql,qr,x,mid+1,r,rc);
}

void func()
{
  cin>>n>>q;
  f(i,1,N) lastOcc[i]=-1;
  f(i,1,n+1)
  {
    cin>>arr[i];
    x[i]=lastOcc[arr[i]];
    lastOcc[arr[i]]=i;
  }

  build();

  while(q--)
  {
    ll l,r;
    cin>>l>>r;
    ll res=qry(l,r,l);
    cout<<res<<"\n";
  }
  
}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
       //cout<<"Case #"<<i<<": ";
       //cout<<"\n";
       func();
    }
     
    return 0;
}


Measured memory_bytes: 164656
N = int(input())
ans = 0
i = 2
 
##N>1で√N>=iまで処理を続ける
while N > 1 and i*i <= N:
  if N % i == 0:
    c = 0
    ##Nがiで割り切れる限り続ける
    ##割った回数を記録
    while N% i == 0:
      N = N / i
      c += 1
    ##[1,3,6,10,15,,,]を作る。2**10だと(2**1)*(2**2)*(2**3),,,累積和
    Y=1
    U=2
    while c>=Y:
      ans=ans+1
      Y=Y+U
      U=U+1
 
  i = i + 1
      
##素数の場合
if N > 1:
  ans = 1 + ans
 
print(ans)

Measured memory_bytes: 9260
#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
int main(){
	
	ll n; cin>>n; ll arr[n]; ll sum = 0;
	for(int i = 0; i < n; i++) { cin>>arr[i]; sum += arr[i];}
	ll ind = -1;
	ll mi = 1000000000000;
	ll cc = 0;
	for(int i = 0; i < n-1; i++){
		cc += arr[i];
		if(abs((sum-cc) - cc) < mi){
			mi = abs((sum-cc) - cc);
		}
	}
	cout<<mi<<"\n";
}













Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;

public class Main {

    static long gcd(long a, long b){
        if(a<b) return gcd(b,a);
        if(b==0) return a;
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int age = sc.nextInt();
        int cost = sc.nextInt();

        int takCost;
        if(age<=5) takCost=0;
        else if(age<=12) takCost = cost/2;
        else takCost = cost;

        System.out.println(takCost);

    }
}

Measured memory_bytes: 20948
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[210000];
int main(){
	int a;scanf("%d",&a);
	scanf("%s",in);
	int ret=mod;
	int cur=0;
	for(int i=0;i<a;i++)if(in[i]=='.')cur++;
	for(int i=0;i<=a;i++){
		ret=min(ret,cur);
		if(i<a){
			if(in[i]=='.'){
				cur--;
			}else cur++;
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 384