akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
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; }

long long n, a, b;

int main(){
  cin >> n >> a >> b;
  long long c = a + b;
  long long res = 0;
  res += (n / c) * a;
  res += min((n % c), a);
  cout << res << endl;
}


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

int main(){
   int n;
   cin >> n;
   VI a(n);
   map<int ,int> num;
   rep(i,n){
       cin >> a.at(i);
       num[a.at(i)]=i+1;      
    }
    for(auto p :num){
      int k=p.first;
      int v=p.second;
      cout << v << " "; 
    }
    cout << endl;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

int main() {
    int X;
    while (cin >> X) {
        bool ok = false;
        for (int a = 0; a <= 20; ++a) {
            for (int b = 0; b <= 20; ++b) {
                for (int c = 0; c <= 20; ++c) {
                    for (int d = 0; d <= 20; ++d) {
                        for (int e = 0; e <= 20; ++e) {
                            int val = 101*a + 102*b + 103*c + 104*d + 105*e;
                            if (val <= X && (X - val) % 100 == 0) ok = true;
                        }
                    }
                }
            }
        }
        if (ok) cout << 1 << endl;
        else cout << 0 << endl;
    }
}



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

int N; //整数
int sum=0; //各桁の合計値
int dig;//整数の1の位 
cin >>N;
int N2 =N; //計算用の整数

while(N2)
{
  dig= N2%10; //10で割った余りで1の位を求める
  sum += dig; //1の位の数を足していく
  N2/=10; //10で割って次の桁へ。10で割り切れなくなったら終了
//cout <<sum <<endl;
}

//N%sum==0が真ならYes 偽ならNo

if(N%sum==0) {cout <<"Yes" <<endl;}
else {cout <<"No"<<endl;}


}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    cout << N*(N-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll inf = 1e18;
const ll mod = 1e9+7;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

struct dsu
{
	ll parent[N];
	ll rank[N];
	ll size[N];
	ll curr;
    
    void init(ll n)
    {
    	curr=n;
    }

	void makeSet(ll i)
	{
		parent[i] = i;
		rank[i] = 0;
		size[i] = 1;
	}

	ll findSet(ll i)
	{
		if(i==parent[i])
			return i;
		parent[i] = findSet(parent[i]);
		return parent[i];
	}

	void unionSet(ll i,ll j)
	{
		ll par1 = findSet(i);
		ll par2 = findSet(j);

		if(par1==par2)
			return;
		curr-=(size[par1]*size[par2]);
		if(rank[par1]==rank[par2])
		{
			rank[par1]++;
			parent[par2] = par1;
			size[par1]+=size[par2];
			size[par2]=0;
		}
		else if(rank[par1]>rank[par2])
		{
			parent[par2] = par1;
			size[par1]+=size[par2];
			size[par2]=0;	
		}
		else
		{
			parent[par1] = par2;
			size[par2]+=size[par1];
			size[par1]=0;
		}
	}
};

typedef struct dsu dsu;

int main()
{
	fast
    ll n,m;
    cin>>n>>m;
    
    dsu dsu1;
    forn(i,1,n+1)
    dsu1.makeSet(i);
    
    ll a[m],b[m];
    forn(i,0,m)
    {
    	cin>>a[i]>>b[i];
    }
       
    ll ans[m];
    dsu1.init(choose2(n)); 
    for(ll i=m-1;i>=0;i--)
    {
    	ans[i] = dsu1.curr;
    	dsu1.unionSet(a[i],b[i]);
    }

    forn(i,0,m)
    cout<<ans[i]<<endl;

	return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

int main() {
    
    ll n,k;
    cin >> n>> k;
    
    ll o,e;
    if(n/2 * 2 ==n){
        o=n/2;
        e=n/2;
    }else{
        o=n/2+1;
        e=n/2;
    }
    
    ll a = n/k;
    ll b = 2*n/k-a;
    
    ll ans;
    
    if(k==1){
        ans = n*n*n;
    }else if(k==2){
        ans = o*o*o+e*e*e;
    }else{
        if(k/2 * 2 ==k){//k:偶数
            ans = a*a*a + b*b*b;
        }else{
            ans = a*a*a;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define P 1000000007
#define N 3005
int f[N][N],d[N][N],Q[N],a[N],F[N][N];
int i,j,k,l,s,n,m;
inline int get(int x,int y,int t) {
    f[x][y]=1ll*f[x][y]*Q[t-d[x][y]-1]%P;
    d[x][y]=t-1;
}
int main() {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    Q[0]=1;
    for (int i=1;i<=3000;i++) Q[i]=Q[i-1]*2ll%P;
    for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++) f[i][j]=(a[i]<a[j]),d[i][j]=0;
    for (int i=1;i<=m;i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        for (int j=1;j<=n;j++) {
            get(j,x,i);
            get(j,y,i);
            get(x,j,i);
            get(y,j,i);
        }
        for (int j=1;j<=n;j++) F[j][x]=f[j][x],F[j][y]=f[j][y],F[y][j]=f[y][j],F[x][j]=f[x][j];
        for (int j=1;j<=n;j++) {
            if (j==x||j==y) continue;
            (f[j][x]+=F[j][y])%=P;
            (f[j][y]+=F[j][x])%=P;
            d[j][x]=d[j][y]=i;
            (f[x][j]+=F[y][j])%=P;
            (f[y][j]+=F[x][j])%=P;
            d[x][j]=d[y][j]=i;
        }
        (f[x][y]+=F[y][x])%=P;
        (f[y][x]+=F[x][y])%=P;
        d[x][y]=d[y][x]=i;
    }
    int ans=0;
    for (int i=1;i<=n;i++)
    for (int j=1;j<i;j++) get(i,j,m+1),(ans+=f[i][j])%=P;
    printf("%d\n",ans);

}

Measured memory_bytes: 106112
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.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;}
const ll INF = 1LL << 60;

ll dp[1100][4400];

int main() {
  int a, b; cin >> a >> b;
  if(1<=a && a<=9 && 1<=b && b<=9) cout << a*b << endl;
  else cout << -1 << endl;
}

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

int main() {
  string s;
  cin>>s;
  if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  if(s=="Cloudy"){
     cout<<"Rainy"<<endl;
     }
  if(s=="Rainy"){
    cout<<"Sunny"<<endl;
  }
}

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

int		main()
{
	int N;
	int ans = 0;

	scanf("%d", &N);
	if (N >= 100)
		N %= 100;
	if (N >= 10)
		N %= 10;
	if (N == 3) {
		printf("bon\n");
		return (0);
	}
	if (N == 0 || N == 1 || N == 6 || N == 8) {
		printf("pon\n");
		return (0);
	}
	else {
		printf("hon\n");
	}
	return (0);
}

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

int N;
const int MAX_N = 1.0e5 + 100;
ll A[MAX_N];

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

    sort(A, A+N);
    ll sum = A[0];
    int cnt = 1;
    for (int i = 1; i < N; i++) {
        if (2 * sum >= A[i]) cnt++;
        else cnt = 1;
        sum += A[i];
    }

    cout << cnt << endl;

    
    return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


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

    ll x = 0, y = 0;
    for(int i = 1; i <= n; i++){
        if(i % k == 0) x++;
        if(i % k == k / 2) y++;
    }

    if(k & 1) cout << x * x * x << endl;
    else cout << x * x * x + y * y * y << endl;

    return 0;
}


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

using namespace std;

int h, w;
char grid[22][22];

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

bool valid(int x, int y)
{
    return (0 <= x && x < h && 0 <= y && y < w && grid[x][y] == '.');
}

int bfs(int x, int y)
{
    map <pair<int, int>, int> dist;
    queue <pair<int, int>> q;

    q.push(make_pair(x, y));
    dist[make_pair(x, y)] = 0;

    while (!q.empty())
    {
        pair <int, int> u = q.front();
        q.pop();

        int x = u.first;
        int y = u.second;

        for (int k = 0; k < 4; k++)
        {
            int i = x + dx[k];
            int j = y + dy[k];

            if (valid(i, j) && dist.find(make_pair(i, j)) == dist.end())
            {
                dist[make_pair(i, j)] = 1 + dist[make_pair(x, y)];
                q.push(make_pair(i, j));
            }
        }
    }

    int farthest = 0;

    for (auto it: dist)
    {
        farthest = max(farthest, it.second);
    }

    return farthest;
}

int main()
{
    cin >> h >> w;

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

    int ans = 0;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (valid(i, j))
                ans = max(ans, bfs(i, j));
        }
    }

    cout << ans << "\n";

    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n; cin >> n;
	vector<Int> a(n), b(n);
	for(Int i=0; i<n; ++i) cin >> a[i] >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if(n % 2 == 1){
		Int m = n / 2;
		cout << b[m] - a[m] + 1 << "\n";
	}else{
		Int x = (a[n/2] + a[(n-1)/2]);
		Int y = (b[n/2] + b[(n-1)/2]);
		cout << y - x + 1 << "\n";
	}
}

Measured memory_bytes: 6368
N = int(input())
G = [[] for i in range(N)]
for v in range(N):
    for w, c in enumerate(map(int, input().split())):
        if c != -1:
            G[v].append((w, c))

from heapq import heappush, heappop, heapify
used = [0]*N
que = [(c, w) for w, c in G[0]]
used[0] = 1
heapify(que)

ans = 0
while que:
    cv, v = heappop(que)
    if used[v]:
        continue
    used[v] = 1
    ans += cv
    for w, c in G[v]:
        if used[w]:
            continue
        heappush(que, (c, w))
print(ans)




Measured memory_bytes: 6652
/*
{

AuThOr Gwj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int main(){
	fastio;
	int n;
	LL rest=0;
	R(n);
	int las=0;
	rb(i,1,n){
		int ai;
		R(ai);
		if(i==1){
			
		}
		else{
			rest+=max(0,las-ai);
			ai=max(las,ai);
		}
		las=ai;
	}
	cout<<rest<<endl;
	return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
    cin>>a>>b>>c;
    for(int i=1;i<=2000;i++)
    {
        if((a*i)%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int n,m,q,a[50],b[50],c[50],d[50],i,j,k;
   int t[10],tt,max;

   scanf("%d %d %d",&n,&m,&q);
   for (i=0;i<q;i++) {
      scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
      a[i]--;b[i]--;
   }
   for (i=0;i<n;i++) t[i]=1;
   max=0;
   for (;;) {
      tt=0;
      for (k=0;k<q;k++)
         if (t[b[k]]-t[a[k]]==c[k]) tt+=d[k];
      if (tt>max) max=tt;
      for (j=1;j<n;j++)
         if (t[j-1]<t[j]) {
            t[j-1]++;
            for (k=0;k<j-1;k++) t[k]=1;
            break;
         }
      if (j==n) {
         if (t[n-1]==m) break;
         t[n-1]++;
         for (k=0;k<n-1;k++) t[k]=1;
      }
   }
   printf("%d\n",max);
   return 0;
}


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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 1000000007;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, std::string s) {
  vector<vector<ll>> dp(N, vector<ll>(N, 0));
  rep(i, N) dp.at(0).at(i) = 1;
  vector<ll> cum(N + 2, 0);

  rep(i, N - 1) {
    FOR(j, 1, N + 1) cum.at(j) = (cum.at(j - 1) + dp.at(i).at(j - 1)) % MOD;

    rep(j, N - i) {
      if (s.at(i) == '<') {
        dp.at(i + 1).at(j) = (cum.at(N - i) - cum.at(j + 1) + MOD) % MOD;
      } else {
        dp.at(i + 1).at(j) = cum.at(j + 1) % MOD;
      }
    }
  }

  cout << dp.at(N - 1).at(0) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  std::string s;
  std::cin >> s;
  solve(N, s);
  return 0;
}


Measured memory_bytes: 73688
import java.util.*;
import java.util.stream.IntStream;

class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i = 0; i < d.length ; i++){
			d[i] = sc.nextInt();
		}
		
		IntStream stream = Arrays.stream(d);
		long MaxStack = stream.distinct().sorted().count();
		
		System.out.println(MaxStack);
	}
}


Measured memory_bytes: 29524
import math
a,b,c = map(int,input().split())
e = math.radians(c)
d = math.fabs(math.sqrt(a*a + b*b - 2*a*b*(math.cos(e))))
L = a + b + d
S = 1/2 * a * b * math.sin(e)
h = 2 * S / a

print(f'{S:.8f}')
print(f'{L:.8f}')
print(f'{h:8f}')


Measured memory_bytes: 5728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		int n;
		int len;
		if (a < b) {
			n = a;
			len = b;
		} else {
			n = b;
			len = a;
		}

		for (int i = 0; i < len; i++)
			System.out.print(n);
		System.out.println();
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


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

char color[5] = "RYGB";

int main()
{
    int h,w,d,x,y;
    scanf("%d %d %d",&h,&w,&d);
    for(int i = 1 ;i <= h; ++i)
    {
        for(int j = 1; j <= w; ++j)
        {
            //映射坐标，+500是防止出现负数，都+500是保持俩数的奇偶性不变
            x = (i+j+500)/d;
            y = (i-j+500)/d;
            //根据坐标奇偶性来判断颜色
            putchar(color[(x%2)*2+y%2]);
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>

using namespace std;

#define ll long long
#define ull unsigned long long
const ll MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	if (N >= 30){
	cout << "Yes" << "\n";
	} else {
	cout << "No" << "\n";		
	}


	return 0;
}


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

int main(){
  int five_hun,hun,fifty,target;
  cin>>five_hun>>hun>>fifty>>target;
  int total=five_hun+hun+fifty;
    int count=0;
  for(int i=0;i<five_hun+1;i++){
    for(int j=0;j<hun+1;j++){
     for(int k=0;k<fifty+1;k++){
       if((k*50+j*100+500*i)==target){count++;}
     }
    }
  }

  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) (x.begin(), x.end())

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a, b;
    cin >> a >> b;
    if(a%b==0) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 256
/* ex6_2
   moka223711 */

#include <stdio.h>
#include <string.h>
#define SIZE 101

int main(void){
    char str[SIZE], ans;
    int len;
    scanf("%s", str);
    
    len = strlen(str);
    
    printf("%c%d%c", str[0], len - 2, str[len - 1]);
    
    return 0;
}



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

x = sum(a)
for i in range(n):
    if a[i]>b[i]:
        a[i] -= b[i]
        b[i] = 0
    else:
        b[i] -= a[i]
        a[i] = 0
    a[i+1] = max(0, a[i+1]-b[i])
print(x-sum(a))

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int p, q, r;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> p >> q >> r;
	int ans = min({p+q, q+r, r+p});
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;

int main() {
	int n, t, a;
	cin >> n;
	cin >> t;
	cin >> a;

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

	int cost = 0;
	double base = (t - a) / 0.006;
	double comp = abs(base - h[0]);
	for (int i = 1; i < n; ++i)
	{
		double a = abs(base - h[i]);
		if (a < comp){
			comp = a;
			cost = i;
		}
	}

	std::cout << cost+1 << endl;

	return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())

ans = ""

for i in range(tx-sx):
    ans += "R"
for i in range(ty-sy):
    ans += "U"
for i in range(tx-sx):
    ans += "L"
for i in range(ty-sy):
    ans += "D"

ans += "D"
for i in range(tx-sx+1):
    ans += "R"
for i in range(ty-sy+1):
    ans += "U"
ans += "L"

ans += "U"
for i in range(tx-sx+1):
    ans += "L"
for i in range(ty-sy+1):
    ans += "D"
ans += "R"
print(ans)


Measured memory_bytes: 43484
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
using namespace std;

const int MOD = 1000000007;

enum EAlphabet {

	A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

};

int main() {

	string str;
	bool check[26];
	for (int i = 0; i < 26; i++)check[i] = false;

	cin >> str;

	for (int i = 0; i < str.size(); i++) {

		if (str[i] == 'a')check[A] = true;
		if (str[i] == 'b')check[B] = true;
		if (str[i] == 'c')check[C] = true;
		if (str[i] == 'd')check[D] = true;
		if (str[i] == 'e')check[E] = true;
		if (str[i] == 'f')check[F] = true;
		if (str[i] == 'g')check[G] = true;
		if (str[i] == 'h')check[H] = true;
		if (str[i] == 'i')check[I] = true;
		if (str[i] == 'j')check[J] = true;
		if (str[i] == 'k')check[K] = true;
		if (str[i] == 'l')check[L] = true;
		if (str[i] == 'm')check[M] = true;
		if (str[i] == 'n')check[N] = true;
		if (str[i] == 'o')check[O] = true;
		if (str[i] == 'p')check[P] = true;
		if (str[i] == 'q')check[Q] = true;
		if (str[i] == 'r')check[R] = true;
		if (str[i] == 's')check[S] = true;
		if (str[i] == 't')check[T] = true;
		if (str[i] == 'u')check[U] = true;
		if (str[i] == 'v')check[V] = true;
		if (str[i] == 'w')check[W] = true;
		if (str[i] == 'x')check[X] = true;
		if (str[i] == 'y')check[Y] = true;
		if (str[i] == 'z')check[Z] = true;

	}

	if (!check[A]) {

		cout << "a" << endl;
		goto qwe;

	}
	if (!check[B]) {

		cout << "b" << endl;
		goto qwe;

	}
	if (!check[C]) {

		cout << "c" << endl;
		goto qwe;

	}
	if (!check[D]) {

		cout << "d" << endl;
		goto qwe;

	}
	if (!check[E]) {

		cout << "e" << endl;
		goto qwe;

	}
	if (!check[F]) {

		cout << "f" << endl;
		goto qwe;

	}
	if (!check[G]) {

		cout << "g" << endl;
		goto qwe;

	}
	if (!check[H]) {

		cout << "h" << endl;
		goto qwe;

	}
	if (!check[I]) {

		cout << "i" << endl;
		goto qwe;

	}
	if (!check[J]) {

		cout << "j" << endl;
		goto qwe;

	}
	if (!check[K]) {

		cout << "k" << endl;
		goto qwe;

	}
	if (!check[L]) {

		cout << "l" << endl;
		goto qwe;

	}
	if (!check[M]) {

		cout << "m" << endl;
		goto qwe;

	}
	if (!check[N]) {

		cout << "n" << endl;
		goto qwe;

	}
	if (!check[O]) {

		cout << "o" << endl;
		goto qwe;

	}
	if (!check[P]) {

		cout << "p" << endl;
		goto qwe;

	}
	if (!check[Q]) {

		cout << "q" << endl;
		goto qwe;

	}
	if (!check[R]) {

		cout << "r" << endl;
		goto qwe;

	}
	if (!check[S]) {

		cout << "s" << endl;
		goto qwe;

	}
	if (!check[T]) {

		cout << "t" << endl;
		goto qwe;

	}
	if (!check[U]) {

		cout << "u" << endl;
		goto qwe;

	}
	if (!check[V]) {

		cout << "v" << endl;
		goto qwe;

	}
	if (!check[W]) {

		cout << "w" << endl;
		goto qwe;

	}
	if (!check[X]) {

		cout << "x" << endl;
		goto qwe;

	}
	if (!check[Y]) {

		cout << "y" << endl;
		goto qwe;

	}
	if (!check[Z]) {

		cout << "z" << endl;
		goto qwe;

	}
	cout << "None" << endl;

	qwe:

	return 0;
}

Measured memory_bytes: 512
let countdiv a b ct = if b mod a == 0 then ct+1 else ct;;
let rec g a b c d =
  let ct = countdiv a c d in
  match a with
    x when x = b -> ct
  | x -> g (x+1) b c ct;;
let f x y z =
  Printf.printf "%d\n" (g x y z 0);;
let () = Scanf.scanf "%d %d %d\n" f;;

Measured memory_bytes: 2388
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, m;
	scanf("%d%d", &n, &m);
	string s;
	scans(s);
	reverse(all(s));
	int a = 0;
	vector<int> ans;
	bool f = false;
	for (int i = 0; i < n;) {
		a = min(i + m, n);
		f = false;
 		while (a > i) {
			if (s[a] == '0') {
				ans.pb(a - i);
				f = true;
				break;
			}
			--a;
		}
		if (!f) {
			puts("-1");
			Please AC;
		}
		i = a;
	}
	reverse(all(ans));
	for (const auto& aa : ans)printf("%d\n", aa);

	Please AC;
}

Measured memory_bytes: 1080
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ld,ld> ii;
const int maxn = 4e3 + 5;
const int mod = 998244353;
const int logn = log2(maxn) + 1;

int cnt[maxn];
int fac[maxn];
int r[maxn] , rfac[maxn] , p[maxn];
int n , k;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    r[1] = 1;
    for(int i = 2 ; i < maxn ; ++i){
        r[i] = (mod - (ll)(mod / i) * r[mod % i] % mod);
    }
    fac[0] = rfac[0] = p[0] = 1;
    for(int i = 1 ; i < maxn ; ++i){
        fac[i] = (ll)fac[i - 1] * i % mod;
        rfac[i] = (ll)rfac[i - 1] * r[i] % mod;
        p[i] = p[i - 1] * 2 % mod;
    }
    cin >> k >> n;
    for(int i = 1 ; i <= k ; ++i){
        for(int j = i ; j <= k ; ++j){
            cnt[i + j]++;
        }
    }
    auto C = [&](int k , int n){
        if(k > n || n < 0)return 0ll;
        return 1ll * fac[n] * rfac[k] % mod * rfac[n - k] % mod;
    };
    for(int i = 2 ; i <= 2 * k ; ++i){
        int res = 0;
        for(int j = 0 ; j <= cnt[i] ; ++j){
            res += (ll)C(j + k - 2 * cnt[i] - 1 , n + k - 2 * cnt[i] - 1) * C(j,cnt[i]) % mod * p[j] % mod;
            if(res >= mod)res -= mod;
        }
        cout << res << endl;
    }
}


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

int main(){
    int w,h;
    while(1){
        cin>>w>>h;  if(w==0)break;
        char tile[h][w];    //タテｘヨコ
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++)cin>>tile[i][j];
        }
//        for(int i=0;i<h;i++){
//            for(int j=0;j<w;j++)cout<<tile[i][j]<<" ";
//            cout<<endl;
//        }

        int ans=1;

        for(int a=0;a<w*h;a++){

            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){

                    if(tile[i][j]=='@'){
                        tile[i][j]='#';

                        if(j<w-1 && tile[i][j+1]=='.'){
                            ans++;
                            tile[i][j+1]='@';
                        }
                        if(j>0 && tile[i][j-1]=='.'){
                            ans++;
                            tile[i][j-1]='@';
                        }
                        if(i<h-1 && tile[i+1][j]=='.'){
                            ans++;
                            tile[i+1][j]='@';
                        }
                        if(i>0 && tile[i-1][j]=='.'){
                            ans++;
                            tile[i-1][j]='@';
                        }

//                        for(int b=0;b<h;b++){
//                            for(int c=0;c<w;c++)cout<<tile[b][c];
//                            cout<<endl;
//                        }
//                        cout<<endl;
                        break;

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



Measured memory_bytes: 3052
n=int(input())
p=[int(input()) for _ in range(n)]

total=sum(p)

if total%10!=0:
  ans=total
  print(ans)
  exit()
  
p.sort()
found=False
for q in p:
  if q%10!=0:
    sub=q
    found=True
    break
    
if found:
  ans=total-sub
  print(ans)
  exit()

ans=0
print(ans)

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

template<class T> inline void chmax(T& a, T b){
	if(a < b){
		a = b;
		return;
	}
	return;
}

int main(){
	int n;
	std::cin >> n;
	std::vector<long long> a(n), b(n), c(n);
	for(int i=0; i<n; i++){
		std::cin >> a[i] >> b[i] >> c[i];
	}

	std::vector<std::vector<long long>> dp(n+1, std::vector<long long>(3));
	dp[1][0] = a[0];
	dp[1][1] = b[0];
	dp[1][2] = c[0];

	for(int i=1; i<n; i++){
		dp[i+1][0] = std::max(dp[i][1]+a[i], dp[i][2]+a[i]);
		dp[i+1][1] = std::max(dp[i][0]+b[i], dp[i][2]+b[i]);
		dp[i+1][2] = std::max(dp[i][0]+c[i], dp[i][1]+c[i]);
	}

	long long ans=0;
	for(int i=0; i<3; i++){
		chmax(ans, dp[n][i]);
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int main()
{
    string S;

    cin >> S;

    if (S[0] == 'A')
    {
        cout << 'T' << endl;
    }
    else if (S[0] == 'T')
    {
        cout << 'A' << endl;
    }
    else if (S[0] == 'C')
    {
        cout << 'G' << endl;
    }
    else
    {
        cout << 'C' << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define re register
#define ll long long
#define int ll
#define get getchar()
#define in inline
in int read()
{
	int t=0; char ch=get;
	while(ch<'0' || ch>'9') ch=get;
	while(ch<='9' && ch>='0') t=t*10+ch-'0', ch=get;
	return t;
}
const int _=2e5+5;
int n,q,A,B,x[_];
ll lazy[_<<4],min1[_<<4],min2[_<<4];
in void pushdown(int k)
{
	if(lazy[k]==0) return ;
	int x=lazy[k];
	lazy[k]=0;
	lazy[k<<1]+=x;
	lazy[k<<1|1]+=x;
	min1[k<<1]+=x;
	min1[k<<1|1]+=x;
	min2[k<<1]+=x;
	min2[k<<1|1]+=x;
}
in void update(int k,int l,int r,int x,int y)
{
	if(l==r)
	{
		min1[k]=min(min1[k],(ll)(y-l));
		min2[k]=min(min2[k],(ll)(y+l));
		return;
	}
	pushdown(k);
	int mid=l+r>>1;
	if(x<=mid) update(k<<1,l,mid,x,y);
	else update(k<<1|1,mid+1,r,x,y);
	min1[k]=min(min1[k<<1],min1[k<<1|1]);
	min2[k]=min(min2[k<<1],min2[k<<1|1]);
}
/*#define ls(_o) (_o << 1)
#define rs(_o) ((_o << 1) | 1)
ll query1(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min1[tree]);
        int mid = (l + r) >> 1;
        pushdown(tree);
        if (rl > mid)
            return (query1(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query1(rl, rr, l, mid, ls(tree)));
        return (min(query1(rl, mid, l, mid, ls(tree)), query1(mid + 1, rr, mid + 1, r, rs(tree))));
    }
ll query2(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min2[tree]);
        int mid = (l + r) >> 1;
        pushdown(tree);
        if (rl > mid)
            return (query2(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query2(rl, rr, l, mid, ls(tree)));
        return (min(query2(rl, mid, l, mid, ls(tree)), query2(mid + 1, rr, mid + 1, r, rs(tree))));
		}*/

  in int query1(int k,int l,int r,int x,int y)
{
//	cout<<1<<":: "<<k<<' '<<l<<' '<<r<<' '<<x<<' '<<y<<endl;
	if(l==x && r==y) return min1[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(y<=mid) return query1(k<<1,l,mid,x,y);
	if(x>mid) return query1(k<<1|1,mid+1,r,x,y);
	return min(query1(k<<1,l,mid,x,mid),query1(k<<1|1,mid+1,r,mid+1,y));
	}
in int query2(int k,int l,int r,int x,int y)
{
//	cout<<2<<":: "<<k<<' '<<l<<' '<<r<<' '<<x<<' '<<y<<endl;
	if(l==x && r==y) return min2[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(y<=mid) return query2(k<<1,l,mid,x,y);
	if(x>mid) return query2(k<<1|1,mid+1,r,x,y);
	return min(query2(k<<1,l,mid,x,mid),query2(k<<1|1,mid+1,r,mid+1,y));
	}
in int getans(int k,int l,int r)
{
	if(l==r) return min1[k]+l;
	pushdown(k);
	int mid=l+r>>1;
	return min(getans(k<<1,l,mid), getans(k<<1|1,mid+1,r));
}
signed main()
{
	n=read(),q=read(),A=read(),B=read();
	x[0]=A;
	memset(min1,0x3f,sizeof(min1));
	memset(min2,0x3f,sizeof(min2));
	update(1,1,n,B,0);
	for(re int i=1;i<=q;i++)
	{
		x[i]=read();
		//int qwe=min(query1(1, x[i], 1, n, 1) + x[i], query2(x[i], n, 1, n, 1) - x[i]);
		int qwe=min(query1(1,1,n,1,x[i])+x[i],query2(1,1,n,x[i],n)-x[i]);
		lazy[1]+=abs(x[i]-x[i-1]);
		min1[1]+=abs(x[i]-x[i-1]);
		min2[1]+=abs(x[i]-x[i-1]);
		update(1,1,n,x[i-1],qwe);
	}
	cout<<getans(1,1,n);
}


Measured memory_bytes: 58368
#include <iostream>
#include <vector>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int N, M;
Graph G;
vector<int> us, vs;

bool rec(int v, int p, int target, long long &path) {
    if (v == target) {
        path = 0;
        return true;
    }
    for (auto e : G[v]) {
        if (e.first == p) continue;
        if (rec(e.first, v, target, path)) {
            path |= (1LL<<e.second);
            return true;
        }
    }
    return false;
}

long long solve() {
    vector<long long> paths(M, 0);
    for (int i = 0; i < M; ++i) rec(us[i], -1, vs[i], paths[i]);
    long long res = 0;
    for (long long bit = 0; bit < (1<<M); ++bit) {
        long long val = 0;
        for (int i = 0; i < M; ++i) if (bit & (1LL<<i)) val |= paths[i];
        long long remnum = N-1 - __builtin_popcountl(val);
        if (__builtin_popcountl(bit) % 2 == 0) res += 1LL<<remnum;
        else res -= 1LL<<remnum;
    }
    return res;
}

int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N-1; ++i) {
        int x, y; cin >> x >> y; --x, --y;
        G[x].emplace_back(y, i);
        G[y].emplace_back(x, i);
    }
    cin >> M;
    us.resize(M), vs.resize(M);
    for (int i = 0; i < M; ++i) {
        cin >> us[i] >> vs[i];
        --us[i], --vs[i];
    }
    cout << solve() << endl;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

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

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	int s, w;
	cin >> s >> w;
	if(w >= s) cout << "unsafe\n";
	else cout << "safe\n";	
	return 0;
}

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

// (P) Maximize obj = sum(flow[lk], fr(lk) == src)
//     subject to
//         [1] 0 <= flow[lk] <= Capa[lk]
//         [2] sum(flow[lk], to(lk) == nd) == sum(flow[lk], fr(lk) == nd)
//             for each nd != s, t

// Ford-Fulkerson Algorithm:
// Step 1. Make residual network by current network flow.
// Step 2. Find s-t path in the residual network. If not exit, finish.
// Step 3. Calculate maximum flow in the s-t path of Step 2.
// Step 4. Make network flow by the result of Step 3. Go to Step 1.

const int INF = 1 << 29;

void print_adjacency_list(const vector< vector< tuple<int, int, int> > > &adjList)
{
  cout << "st_nd: (ed_nd, capa, rev_ind), ..." << endl;
  for (int st_nd = 0; st_nd < adjList.size(); ++st_nd) {
    cout << st_nd << ":";
    for (auto itr = adjList[st_nd].begin(); itr != adjList[st_nd].end(); ++itr) {
      int ed_nd, capa, rev_ind; tie(ed_nd, capa, rev_ind) = *itr;
      cout << " (" << ed_nd << ", " << capa << ", " << rev_ind << ")";
    }
    cout << endl;
  }
}

int find_augmenting_path(const int crrnt_nd, const int sink_nd,
                         const int min_capa_up_here, vector<bool> &seen,
                         vector< vector< tuple<int, int, int> > > &adj)
{
  if (crrnt_nd == sink_nd) { return min_capa_up_here; }
  seen[crrnt_nd] = true;
  for (auto itr = adj[crrnt_nd].begin(); itr != adj[crrnt_nd].end(); ++itr) {
    int next_nd, rev_ind; tie(next_nd, ignore, rev_ind) = *itr;
    int &capa = get<1>(*itr);
    if (!seen[next_nd] && capa > 0) {
      int flow = find_augmenting_path(next_nd, sink_nd,
                                      min(min_capa_up_here, capa), seen, adj);
      if (flow > 0) {
        int &rev_capa = get<1>(adj[next_nd][rev_ind]);
        capa -= flow;
        rev_capa += flow;
        return flow;
      } 
    }
  }
  return 0;
}

int ford_fulkerson(const int src_nd, const int sink_nd,
                   vector< vector< tuple<int, int, int> > > adj)
{
  int max_flow = 0;
  int n_nodes = adj.size();
  while (true) {
    vector<bool> seen(n_nodes, false); // TODO
    int flow = find_augmenting_path(src_nd, sink_nd, INF, seen, adj);
    if (flow == 0) { return max_flow; }
    max_flow += flow;
  }
}

int main(int argc, char *argv[])
{
  int n_nodes, n_links;
  cin >> n_nodes >> n_links;
  vector< vector< tuple<int, int, int> > > adjList(n_nodes);
  for (int i = 0; i < n_links; ++i) {
    int st_nd, ed_nd, capa;
    cin >> st_nd >> ed_nd >> capa;
    adjList[st_nd].push_back(make_tuple(ed_nd, capa, adjList[ed_nd].size()));
    adjList[ed_nd].push_back(make_tuple(st_nd, 0, adjList[st_nd].size() - 1));
  }
  int src_nd = 0, sink_nd = n_nodes - 1;
  cout << ford_fulkerson(src_nd, sink_nd, adjList) << endl;
  return 0;
}

Measured memory_bytes: 3148
N = gets.to_i
S = gets.chomp

p (0..N-2).inject(0) {|res, i|
    type = S.chars.uniq.inject(0) {|sum, j|
        judge = [S[0..i], S[i+1..-1]].map{|k| k.include?(j)}
        sum = judge.all? ? sum + 1 : sum
    }
    
    res = [res, type].max
}

Measured memory_bytes: 1916
#include <iostream>
#include<vector>
#include<algorithm>
#include<utility>

#define mod 1000000007

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
vector<P> par;//???????????¨??????
vector<int> ran;//??¨????????????

P find(int a) {
	if (par[a].first == a)return P(a,0);
	else {
		int ap=find(par[a].first).first;
		int ad = find(par[a].first).second + par[a].second;
		return par[a] = P(ap,ad);
	}
}
bool same(int a, int b) {
	if (find(a).first == find(b).first)return true;
	else return false;
}
int unite(int a, int b, int d) {
	int ra = find(a).first;
	int rb = find(b).first;
	if (ran[ra] < ran[rb]) {
		par[ra] = P(rb, d + find(b).second - find(a).second);
	}
	else {
		par[rb] = P(ra, -d - find(b).second + find(a).second);
	}
	return 0;
}
int diff(int a, int b) {
	return find(a).second - find(b).second;
}

int main() {
	while (true) {
		int n, m;
		cin >> n >> m;//100,000
		if (n == 0 && m == 0)return 0;
		par.resize(0); ran.resize(0);
		par.resize(n);  ran.resize(n,1);
		for (int i = 0; i < n; i++)par[i] = P(i,0);
		for (int i = 0; i < m; i++) {
			char L;
			cin >> L;
			if (L == '!') {
				int a, b, d;
				cin >> a >> b >> d;
				a--; b--;
				if (!same(a, b)) {
					unite(a, b, d);
				}
			}
			else {//????????¨??????outuput??????
				int a, b;
				cin >> a >> b;
				a--; b--;
				if (!same(a, b)) {
					cout << "UNKNOWN"<<endl;
				}
				else {
					cout << diff(a, b)<<endl;
				}

			}
		}
		

	}

	return 0;
}

Measured memory_bytes: 5992
#include <iostream>
using namespace std;
char chess(int h,int w){

    
    if((h+w)%2==0){
        return '#';
    }
    return '.';
}
    int main(){
        int H,W;
        while(1){
        cin >> H >> W;
        if(H==0 && W==0)break;
        
        for(int j=0;j<H;j++){
            for(int i=0;i<W;i++){
                cout << chess(i,j);
            }
            cout << endl;
        }
        cout << endl;
    }
    }


Measured memory_bytes: 3068
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = [set(LI()[1:]) for _ in range(n)]
        s = set((LI()[1:]))
        r = -1
        for c,i in zip(a,range(1,n+1)):
            if not (s - c):
                if r != -1:
                    r = -1
                    break
                r = i
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




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


int main() {
	string s, t; cin >> s; cin >> t;
	int ans = 1000;
	int tx = t.size(), n = s.size();

	for (int i = 0; i < n - tx + 1; i++) {
		int cnt = tx;
		for (int k = 0; k < tx; k++) {
			if (s[i + k] == t[k]) {
				--cnt;
			}
		}

		ans = min(ans, cnt);

	}

	cout << ans;
	return 0;

}

Measured memory_bytes: 3604