akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v, p):
    for next_v in g[v]:
        if next_v == p:
            continue
        cnt[next_v] += cnt[v]
        dfs(next_v, v)


N, Q = map(int, input().split())

g = {i:[] for i in range(N+1)}
cnt = {i:0 for i in range(N+1)}
for _ in range(N - 1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

dfs(1, -1)

print(*list(cnt.values())[1:])

Measured memory_bytes: 265060
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

ll const mod = 7+(ll)1e9, N = 100100;
int n, k;
vector< int > g[N];
ll ans;
void dfs(int u, int par) {
  int cc = g[u].size();
  if( par == 0 ) {
    ans = (ans * k) % mod;
  } else {
    cc--;
  }
  for(ll t=k-1-(par!=0),v=1; v<=cc; v++,t--)
    ans = (ans * t) % mod;
  for(int v: g[u]) {
    if( v == par ) continue;
    dfs(v, u);
  }
}

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

  cin >> n >> k;  
  for(int i=1; i<n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }

  for(int i=1; i<=n; i++) {
    if( g[i].size() >= k ) {
      cout << 0 << endl;
      return 0;
    }
  }

  ans = 1;
  dfs(1, 0);
  cout << ans << endl;

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


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

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

    if(A == B){
        cout << "Draw" << endl;
        return 0;
    }

    if(A == 1){
        cout << "Alice" << endl;
        return 0;
    }
    else if(B == 1){
        cout << "Bob" << endl;
        return 0;
    }

    if(A > B){
        cout << "Alice" << endl;
    }
    else if(A < B){
        cout << "Bob" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
using namespace std;

#define DB(x)

int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}


class coodi
{
public:
    coodi(int t, int x, int y):m_t(t),m_x(x),m_y(y){}
    ~coodi(){}
    bool canGo( coodi& before )
    {
        int distance = abs(m_x - before.m_x) + abs(m_y - before.m_y);
        int timediff = m_t - before.m_t;
        if( timediff - distance < 0 ){
            return false;
        }
        if( distance-timediff % 2 == 1 ){
            return false;
        }
        return true;
    }
private:
    int m_t;
    int m_x;
    int m_y;
};

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    
    map<string,int> m;
    m.insert(std::make_pair(string("SUN"),7));
    m.insert(std::make_pair(string("MON"),6));
    m.insert(std::make_pair(string("TUE"),5));
    m.insert(std::make_pair(string("WED"),4));
    m.insert(std::make_pair(string("THU"),3));
    m.insert(std::make_pair(string("FRI"),2));
    m.insert(std::make_pair(string("SAT"),1));

    cout << m.at(S);
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    int N;
    cin >> N;
    int A[N];
    REP(i,N) cin >> A[i];
    bool exist=true;
    for(int i=0;i<N;++i)
    {
        if(A[i]%2==0){
        if(A[i]%3==0) {
            continue;
        }
        else{
            if(A[i]%5==0){
                continue;
            }
            else{
                exist=false;
                break;
            }
        }
    }
    else{
        continue;
    }
    }
    if(exist==true) cout << "APPROVED";
    else cout << "DENIED";
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

char c[303][303];

int ans[303][303];

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    int fi = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            cin >> c[i][j];
            if (c[i][j] == '#' && !fi){
                fi = i;
            }
        }
    }
    for (int i = fi, z = 0; i <= n; i++){
        int cnt = 0;
        for (int j = 1; j <= m; j++){
            cnt += c[i][j] == '#';
        }
        if (!cnt){
            for (int j = 1; j <= m; j++){
                ans[i][j] = ans[i-1][j];
            }
        }
        else{
            z++;
            for (int j = 1; j <= m; j++){
                ans[i][j] = z;
                if (c[i][j] == '#'){
                    cnt--;
                    if (cnt){
                        z++;
                    }
                }
            }
        }
    }
    for (int i = 1; i < fi; i++){
        for (int j = 1; j <= m; j++){
            ans[i][j] = ans[fi][j];
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            cout << ans[i][j] << " ";
        }
        cout << ndl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a,b;
  cin >> a >> b;
  
  int x = (a + b) / 2;
  
  if( (((a + b ) % 2) == 0) ){
    cout << x << endl;
  }else{
    cout << x + 1 << endl;
  }
 
  
}

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

#define M_PI       3.14159265358979323846   // pi

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

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e15;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> vs(3 * n);
    rep(i, 3 * n) {
        cin >> vs[i];
        vs[i]--;
    }
    vector<vector<ll>> dp(n, vector<ll>(n, -3*n));
    vector<ll> dpMax(n, -3 * n);
    ll cMax = 0;
    ll threes = 0;
    dp[vs[0]][vs[1]] = 0;
    dp[vs[1]][vs[0]] = 0;
    dpMax[vs[0]] = 0;
    dpMax[vs[1]] = 0;
    vector<t3> updates;
    updates.reserve(n* n);
    for (int i = 0; i < n - 1; i++) {
        updates.clear();
        const ll* buffer = &vs[3*i+2];
        //3枚同じ
        if (buffer[0] == buffer[1] and buffer[1] == buffer[2]) {
            threes++;
            continue;
        }
        //2枚同じ
        if (buffer[0] == buffer[1]) {
            ll p = buffer[0];
            ll k = buffer[2];
            for (int j = 0; j < n; j++) {
                updates.emplace_back(j, k, dp[p][j] + 1);
                updates.emplace_back(j, k, dp[j][p] + 1);
            }
        }
        else if (buffer[1] == buffer[2]) {
            ll k = buffer[0];
            ll p = buffer[2];
            for (int j = 0; j < n; j++) {
                updates.emplace_back(j, k, dp[p][j] + 1);
                updates.emplace_back(j, k, dp[j][p] + 1);
            }
        }
        else if (buffer[0] == buffer[2]) {
            ll k = buffer[1];
            ll p = buffer[2];
            for (int j = 0; j < n; j++) {
                updates.emplace_back(j, k, dp[p][j] + 1);
                updates.emplace_back(j, k, dp[j][p] + 1);
            }
        }
        //3枚ばらばらでカウント
        ll p = buffer[0];
        ll k = buffer[1];
        ll l = buffer[2];
        updates.emplace_back(k, l, dp[p][p] + 1);
        updates.emplace_back(p, l, dp[k][k] + 1);
        updates.emplace_back(p, k, dp[l][l] + 1);
        rep(j, 3) {
            rep(a, j) {
                ll p = buffer[a];
                ll k = buffer[j];
                updates.emplace_back(p, k, cMax);
            }
        }
        rep(j, 3) {
            ll p = buffer[j];
            rep(k, n) {
                updates.emplace_back(k, p, dpMax[k]);
            }
        }
        for (auto t : updates) {
            ll j, k, v;
            tie(j, k, v) = t;
            chmax(dp[j][k], v);
            chmax(dp[k][j], v);
            chmax(dpMax[j], v);
            chmax(dpMax[k], v);
            chmax(cMax, v);
        }
    }
    ll u = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == vs[3 * n - 1] && i == j) {
                chmax(u, dp[i][i] + 1);
            }
            else {
                chmax(u, dp[i][j]);
            }
        }
    }
    cout << u + threes << endl;
    return 0;
}


Measured memory_bytes: 19336
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

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

	while(n>=500){
		n-=500;
	}
	if(n<=a){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>

#define xx first
#define yy second
#define mp make_pair
#define pb push
using namespace std;

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

void play(int h, int w, int c,int mas[10][10],int cnt){
    //cout << "x" << endl;
    //cout << endl;
    int con[10][10]={0};

    int ans=0;

    con[0][0] = 1;

    queue < pair <int,int> > qu;

    qu.pb(mp(0,0));

    while(qu.size() > 0){
        int xx = qu.front().xx;
        int yy = qu.front().yy;

        qu.pop();

        for(int i = 0 ; i < 4 ; i++){
            int xxx = xx + dx[i];
            int yyy = yy + dy[i];

            if(xxx >=0 && xxx < h && yyy >=0 && yyy < w){
                if(mas[xxx][yyy] == mas[xx][yy] && con[xxx][yyy] == 0){
                    con[xxx][yyy] = 1;
                    qu.pb(mp(xxx,yyy));
                }
            }
        }
        //cout << qu.size() << endl;
    }
    for(int i = 0 ; i < h ; i++){
        for(int j= 0 ; j < w ;j++){
            if(con[i][j] == 1) ans++;
        }
    }

    /*
    for(int i = 0 ; i < h ; i++){
        for(int j= 0 ; j < w ;j++){
            cout << con[i][j] << " ";
        }

        cout << " | ";
        for(int j= 0 ; j < w ;j++){
            cout << mas[i][j] << " ";
        }
        cout << endl;
    }
    */
    if(cnt == 5){
        if(mas[0][0] == c){
            anss = max(anss,ans);
        }
        return;
    }

    int poss[10] = {0};

    for(int i = 0 ; i < h ; i++){
        for(int j = 0 ; j < w ; j++){
            if(con[i][j] == 1){
                for(int k = 0 ; k < 4 ; k++){
                    int xx = i +dx[k];
                    int yy = j + dy[k];

                    if(xx >= 0 && xx < h && yy >=0 && yy < w){
                        if(mas[xx][yy] != mas[i][j]) poss[mas[xx][yy]] = 1;
                    }
                }
            }
        }
    }

    int m[10][10];

    for(int col = 1 ; col <= 6 ; col++){
        for(int i = 0 ; i < h ; i++){
            for(int j = 0 ; j < w ; j++){
                m[i][j] = mas[i][j];
            }
        }

        if(1){
            for(int i = 0 ; i < h ; i++){
                for(int j = 0 ; j < w ; j++){
                    if(con[i][j] == 1) m[i][j] = col;
                }
            }

            int cntt = cnt;
            cntt++;
            play(h,w,c,m,cntt);
        }
    }

}
main(){
    int h,w,c;

    while(cin >> h >> w >> c,h!=0){
        int mas[10][10];

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

        anss = 0;
        play(h,w,c,mas,0);

        cout << anss << endl;
    }
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <string.h>
#define maxn 500010
int c[30][maxn],n;
char s[maxn];
int lowbit(int x){
	return x&-x;
}
void update(int x,int delta,int *a){
	for(int i=x;i<=n;i+=lowbit(i))a[i]+=delta;
}
int sum(int x,int *a){
	int ret=0;//此处错写成int ret;查了好久
	for(int i=x;i>=1;i-=lowbit(i))ret+=a[i];
	return ret;
}
int main(){
	int i,q,cmd,p,l,r,cnt,j;
	char b[3];
	scanf("%d%s%d",&n,s+1,&q);
	for(i=1;i<=n;i++)update(i,1,c[s[i]-'a']);
	while(q--){
		scanf("%d",&cmd);
		if(cmd==1){
			scanf("%d%s",&p,b);
			update(p,-1,c[s[p]-'a']);
			s[p]=b[0],update(p,1,c[b[0]-'a']);
		}else if(cmd==2){
			scanf("%d%d",&l,&r),cnt=0;
			for(i=0;i<26;i++)cnt+=sum(r,c[i])-sum(l-1,c[i])>0;
			printf("%d\n",cnt);
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N; cin >> N;
  vi32 A(N); cin >> A;
  i64 ans = power(3, N);
  i64 odd = 1;
  rep(i, N) {
    if (A[i] % 2 == 0) odd *= 2; else odd *= 1;
  }
  cout << ans - odd << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include<sstream>
#include <cmath>
using namespace std;
#define pb push_back
#define PB pop_back
#define bk back()
#define fs first
#define se second
#define INF 1e9*2+10
#define sq(x) (x)*(x)
#define eps (1e-7)
#define clr(x) memset((x),0,sizeof (x))
#define cp(a,b) memcpy((a),(b),sizeof (b))

const int maxn=1005;
int W,H,N;
int x1[maxn],x2[maxn],Y1[maxn],Y2[maxn];
int fld[maxn*3][maxn*3];
int dir[4][2]={1,0,0,1,0,-1,-1,0};

int compress(int *x1,int *x2,int w)
{
    vector<int> v;
    for(int i=1;i<=N;i++)
    {
        int tx1,tx2;
        for(int d=-1;d<=1;d++)
        {
            tx1=x1[i]+d;
            tx2=x2[i]+d;
            if(tx1>=0&&tx1<w) v.pb(tx1);
            if(tx2>=0&&tx2<w) v.pb(tx2);
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(int i=1;i<=N;i++)
    {
        x1[i]=lower_bound(v.begin(),v.end(),x1[i])-v.begin();
        x2[i]=lower_bound(v.begin(),v.end(),x2[i])-v.begin();
    }
    return v.size();
}

void solve()
{
    W=compress(x1,x2,W);
    H=compress(Y1,Y2,H);
    clr(fld);
    for(int i=1;i<=N;i++)
    for(int y=Y1[i];y<=Y2[i];y++)
    for(int x=x1[i];x<=x2[i];x++)  fld[y][x]=1;
    int ans=0;
    /*
    for(int x=0;x<W;x++)
    {
        for(int y=0;y<H-1;y++) cout<<fld[x][y]<<" ";
        cout<<fld[x][H-1]<<endl;
    }
    */
    for(int y=0;y<H;y++)
    for(int x=0;x<W;x++)
    {
        if(fld[y][x]) continue;
        fld[y][x]=1;
        ans++;
        queue<pair<int,int> > q;
        q.push(make_pair(x,y));
        while(!q.empty())
        {
            int xx,yy,nx,ny;
            xx=q.front().fs,yy=q.front().se;
            q.pop();
            for(int i=0;i<4;i++)
            {
                nx=xx+dir[i][0];
                ny=yy+dir[i][1];
                if(nx<0||nx>=W||ny<0||ny>=H||fld[ny][nx]) continue;
                fld[ny][nx]=1;
                q.push(make_pair(nx,ny));
            }
        }
    }
    printf("%d\n",ans);
}

int main()
{
    while(~scanf("%d%d",&W,&H)&&W&&H)
    {
        scanf("%d",&N);
        for(int i=1;i<=N;i++)//??¨?????????????????????????????????????????¢??????????????????????????????????????¶?????§???????°±??????.......
        {
            scanf("%d%d%d%d",&x1[i],&Y1[i],&x2[i],&Y2[i]);
            x2[i]-=1;
            Y2[i]-=1;
        }
        solve();
    }
    return 0;
}

Measured memory_bytes: 36756
#include<stdio.h>
int main(void){

  int a,b,c,d,e,f,g,h,j,k,l,m,n,o,x,y;
  int i;

  scanf("%d",&n);
  (y=n%3);
  
    for(i=3;i<n;i++){
      
      (x=i%3);
      
      (a=i%10);
      (b=i-a);
      (c=b/10);
      (d=c%10);
      (e=c-d);
      (f=e/10);
      (g=f%10);
      (h=f-g);
      (j=h/10);
      (k=j%10);
      (l=j-k);
      (m=l/10);
      (o=m%10);
      
      if(x==0){
	printf(" %d",i);
      }else if(a==3){
	printf(" %d",i);
      }else if(d==3){
	printf(" %d",i);
      }else if(g==3){
	printf(" %d",i);
      }else if(k==3){
	printf(" %d",i);
      }else if(o==3){
	printf(" %d",i);
      }
    }
    if(y==0){
      printf(" %d",n);
    }
    printf("\n");
    return 0;
}
	
	       

Measured memory_bytes: 1028
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; i ++) {
            t[i] = sc.nextInt();
            a[i] = sc.nextInt();
        }
        System.out.println(cal(n, t, a));
    }

    private static long cal(final int n, final int[] t, final int[] a) {
        long lastt = t[0];
        long lasta = a[0];
        for (int i = 1; i < n; i ++) {
            if (t[i] > lastt && a[i] > lasta) {
                lastt = t[i];
                lasta = a[i];
            } else {
                long xt = lastt % t[i] == 0 ? lastt /t[i] : lastt/t[i] + 1;
                long xa = lasta % a[i] ==0 ? lasta / a[i] : lasta/a[i] + 1;
                lastt = Math.max(xt, xa) * t[i];
                lasta = Math.max(xt, xa) * a[i];
            }
        }
        return lasta + lastt;
    }
}


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

const int N = 1e5+5;
vector<int> adj[N];
vector<int> indeg(N,0);
vector<int> dist(N,0);
int n,m;

void bfs(){
	queue<int> q;
	for(int i=1; i<=n; ++i){
		if( indeg[i] == 0 ){
			q.push(i);
			dist[i] = 0;
		}
	}
	while(!q.empty()){
		auto x = q.front(); q.pop();
		for( auto y : adj[x] ){
			indeg[y]--;
			dist[y] = max( dist[y] , 1 + dist[x] );
			if( indeg[y] == 0 ){ q.push(y); }
		}
	}
	int max_ans = 0;
	for(int i=1; i<=n; ++i){
		max_ans = max(max_ans, dist[i]);
	}
	cout<<max_ans<<'\n';
}

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

	cin>>n>>m;
	for(int i=0; i<m; ++i){
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		indeg[b]++;
	}
	bfs();
	return 0;

}


Measured memory_bytes: 6528
def main():
    length, sum_num, subarray_sum = map(int, input().split())
    answer = [subarray_sum] * sum_num
    if subarray_sum == 10 ** 9:
        answer += [1] * (length - sum_num)
    else:
        answer += [subarray_sum + 1] * (length - sum_num)
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 12540
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
	int N;
	cin >> N;
	vector<int> a(N);
	int t = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] %2 == 1 && i %2 == 0) t++;
	}
	cout << t << endl;
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<bool>> masu(h, vector<bool>(w, false));
	char tf;
	pair<int, int> tmp;
	queue<pair<int, int>> bfs;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> tf;
			if (tf == '.')masu[i][j] = true;
		}
	}

	int max = 0;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (!masu[i][j])continue;
			vector<vector<int>> use(h, vector<int>(w, -1));
			bfs.push(make_pair(i, j));
			use[i][j] = 0;
			while (!bfs.empty()) {
				tmp = bfs.front();
				bfs.pop();
				int a = tmp.first, b = tmp.second;
				int turn = use[a][b];
				//printf("turn = %d\n", turn);
				if (a > 0 && masu[a - 1][b] && use[a - 1][b] == -1) {
					use[a - 1][b] = turn + 1;
					bfs.push(make_pair(a - 1, b));
				}
				if (b > 0 && masu[a][b - 1] && use[a][b - 1] == -1) {
					use[a][b - 1] = turn + 1;
					bfs.push(make_pair(a, b - 1));
				}
				if (a < h - 1 && masu[a + 1][b] && use[a + 1][b] == -1) {
					use[a + 1][b] = turn + 1;
					bfs.push(make_pair(a + 1, b));
				}
				if (b < w - 1 && masu[a][b + 1] && use[a][b + 1] == -1) {
					use[a][b + 1] = turn + 1;
					bfs.push(make_pair(a, b + 1));
				}
			}

			for (int ii = 0; ii < h; ii++) {
				for (int jj = 0; jj < w; jj++) {
					max = use[ii][jj] > max ? use[ii][jj] : max;
					//printf("%d ", use[ii][jj]);
				}
			}
		}
	}

	printf("%d", max);

	return 0;
}



Measured memory_bytes: 256
N = int(input())

max_a = [0] * N
max_b = [0] * N
max_c = [0] * N
if N>1:
    for i in range(0, N):
        a, b, c = map(int, input().split())
        max_a[i] = max(max_b[i - 1] + a, max_c[i-1] + a)
        max_b[i] = max(max_a[i - 1] + b, max_c[i - 1] + b)
        max_c[i] = max(max_a[i - 1] + c, max_b[i - 1] + c)

    print(max(max_a[-1], max_b[-1], max_c[-1]))
else:
    a, b, c = map(int, input().split())

    print(max(a, b, c))

Measured memory_bytes: 50776
#include <stdio.h>

int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    if(y%2==0 && y/2-x>=0 && 2*x-y/2>=0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<algorithm>
using namespace std;
long long n,m;
long long ans=0;
int main()
{
    int i,j,k;
    cin>>n>>m;
    long long x,y,z;
    
    if(n>m)swap(n,m);
    
    if(n==1)
    {
        if(m==1)
        {
            ans=1;
        }
        else
        {
            ans=m-2;
        }
    }
    else
    {
        ans=(n-2)*(m-2);
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
inf = 10**9+7
dp = [inf] * (N+10)
dp[0] = 0
import numpy as np
for i,h in enumerate(H[:N-1]):
    dp[i+1] = min(dp[i+1],dp[i] + np.abs(h-H[i+1]))
    if i<N-2: dp[i+2] = min(dp[i+2],dp[i] + np.abs(h-H[i+2]))
    
print(dp[N-1])

Measured memory_bytes: 20928
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a[4],s,d,f,g,h,i,j;
	for(i=0;i<3;i++) scanf("%d",&a[i]);
	for(i=0;i<2;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				s=a[i];
				a[i]=a[j];
				a[j]=s;
			}
		}
	}
	d=0;
	for(i=0;i<2;i++) d+=a[i];
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(),vec.end()
#define rep(i,n) for(ll i = 0;i<n;++i)
#define repc(bit,k,n) for (ll bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;cin>>n;
  unordered_map<string, int> card;
  rep(i,n){
    string s;cin>>s;
    card[s]++;
  }
  int m;cin>>m;
  rep(i,m){
    string s;cin>>s;
    card[s]--;
  }
  int ma = 0;
  repi(itr,card){
    ma = max(ma,(*itr).second);
  }
  cout << ma << endl;

  return 0;
}

Measured memory_bytes: 3576
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip> //cout<<setprecision(n)
#define _for(i,n) for(int i = 0; i < n; i++)
#define MOD 1000000007

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

int main() {
  ll n;
  std::cin >> n;
  ll acount[26] = {};
  char c;
  _for(i,n) {
    std::cin >> c;
    acount[c-'a'] ++;
  }
  ll ans = 1;
  _for(i,26) {
    ans = (ans*(acount[i]+1))%MOD;
  }
  std::cout << ans-1 << std::endl;
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t[i];
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (s[i] == s[j]) {
        ans[i]++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (s[i] == t[j]) {
        ans[i]--;
      }
    }
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  int answer = ans[0];
  if (answer < 0) {
    answer = 0;
  }
  cout << answer << endl;
    
}

Measured memory_bytes: 3608
import numpy as np
i4 = np.int32
i8 = np.int64

INF = 1000000000


def solve(s, ch, cw):
    H = s.shape[0]
    W = s.shape[1] - 1
    ah = H + 4
    aw = W + 4

    a = np.full((ah, aw), -1, i4)
    for i in range(H):
        for j in range(W):
            if s[i, j] == 46:
                a[i + 2, j + 2] = INF

    sh1 = np.empty(1000000, i4)
    sw1 = np.empty(1000000, i4)
    p1 = 0
    sh2 = np.empty(1000000, i4)
    sw2 = np.empty(1000000, i4)
    p2 = 0

    dis = 0
    a[ch + 1, cw + 1] = dis
    sh1[p1] = ch + 1
    sw1[p1] = cw + 1
    p1 += 1

    while True:
        while p1 > 0:
            p1 -= 1
            h = sh1[p1]
            w = sw1[p1]
            for i in range(-2, 3):
                for j in range(-2, 3):
                    if ((i == 1 or i == -1) and j == 0) or (i == 0 and (j == 1 or j == -1)):
                        if a[h + i, w + j] > dis:
                            a[h + i, w + j] = dis
                            sh1[p1] = h + i
                            sw1[p1] = w + j
                            p1 += 1
                    else:
                        if a[h + i, w + j] > dis + 1:
                            a[h + i, w + j] = dis + 1
                            sh2[p2] = h + i
                            sw2[p2] = w + j
                            p2 += 1

        dis += 1
        for i in range(p2):
            if a[sh2[i], sw2[i]] == dis:
                sh1[p1] = sh2[i]
                sw1[p1] = sw2[i]
                p1 += 1
        p2 = 0

        if p1 == 0:
            break

    return a


def main(in_file):
    stdin = open(in_file)
    H, W = [int(x) for x in stdin.readline().split()]
    ch, cw = [int(x) for x in stdin.readline().split()]
    dh, dw = [int(x) for x in stdin.readline().split()]
    s = np.frombuffer(np.array(stdin.read()), i4).reshape((H, W + 1))
    a = solve(s, ch, cw)
    ans = a[dh + 1, dw + 1]
    if ans == INF:
        print(-1)
    else:
        print(ans)


def cc_export():
    from numba.pycc import CC
    from numba import int32, int64
    cc = CC('my_module')
    cc.export('solve', (int32[:,:], int64, int64))(solve)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main('/dev/stdin')


Measured memory_bytes: 35592
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=INF; cin>>n;
    vector<ll> a(n,0),s(n+1,0);
    rep(i,n){
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
    rep(i,n-1){
        ll d=abs((s[n]-s[i+1])-s[i+1]);
        ans=min(ans,d);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
typedef long long ll;

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

    vector<int> a(N + 1), b(N + 1);
    for (int i = 1; i <= N; ++i) a[i] = b[i] = N;

    ll black = ll(N - 2) * (N - 2);

    int H = N, W = N;

    while (Q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            if (x < W) {
                for (int i = x; i < W; ++i) {
                    b[i] = H;
                }
                W = x;
            }
            black -= b[x] - 2;

        } else {
            if (x < H) {
                for (int i = x; i < H; ++i) {
                    a[i] = W;
                }
                H = x;
            }
            black -= a[x] - 2;
        }
    }
    cout << black << endl;

    return 0;
}


Measured memory_bytes: 4836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

const long double pi = atan2(0., -1.);
const int N = (int)1e5 + 100;

struct Point
{
    long long x, y;
    int id;
    Point () {}
    Point (long long _x, long long _y, int _id = -1) : x(_x), y(_y), id(_id) {}
    Point operator + (const Point &a) const
    {
        return Point(x + a.x, y + a.y);
    }
    Point operator - (const Point &a) const
    {
        return Point(x - a.x, y - a.y);
    }
    ll operator % (const Point &a) const
    {
        return (ll)x * a.x + (ll)y * a.y;
    }
    ll operator * (const Point &a) const
    {
        return (ll)x * a.y - (ll)y * a.x;
    }
    double length()
    {
        return sqrt(x * x + y * y);
    }
    bool operator < (const Point &a) const
    {
        return x < a.x || (x == a.x && y < a.y);
    }
    Point rotate() const
    {
        return Point(-y, x);
    }
    void scan()
    {
        scanf("%lld%lld", &x, &y);
    }
    void print()
    {
        printf("%lld %lld\n", x, y);
    }
};

Point wall[N];
Point st[N];
int r = 0;

Point minP;

bool cmpPoints(const Point &a, const Point &b)
{
    Point v = a - minP;
    Point u = b - minP;
    if (v * u != 0)
        return v * u > 0;
    return v.length() < u.length();
}

void graham(int n)
{
    minP = *min_element(wall, wall + n);
    sort(wall, wall + n, cmpPoints);
    r = 0;
    for (int i = 0; i < n; i++)
    {
        while (r > 1 && (st[r - 1] - st[r - 2]) * (wall[i] - st[r - 2]) <= 0)
            r--;
        st[r++] = wall[i];
    }
}

long double ans[N];

double getAns(Point v, Point u)
{
    long double ang = atan2(v * u, v % u);
    return ang / 2 / pi;
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        wall[i].scan();
        wall[i].id = i;
    }
    graham(n);

    if (r == 2)
    {
        for (int i = 0; i < r; i++)
            ans[st[i].id] = 0.5;
    }
    else
    {
        for (int i = 0; i < r; i++)
        {
            int pid = (i + r - 1) % r;
            int ni = (i + 1) % r;
            Point A = (st[i] - st[pid]).rotate();
            Point B = (st[ni] - st[i]).rotate();
            ans[st[i].id] = getAns(A, B);
        }
    }

    for (int i = 0; i < n; i++)
        printf("%.10Lf\n", ans[i] );

    return 0;
}


Measured memory_bytes: 2304
#include <iostream>

using namespace std;
 
int main() {
	int a, b, c; cin >> a >> b >> c;
	int tmp = a % b, choose = a;
	bool flag = false;
	do {
		if (choose % b == c) {
			flag = true;
			break;
		}
		choose += a;
	} while (tmp != choose % b);
	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
s = input()
s = s[::-1]
loc = 0
anslist=[]
while True:
  if loc >= n-m:
    anslist.append(n-loc)
    break
    quit()
  next = m
  while s[loc+next]=="1":
    next-=1
    if next == 0:
      print(-1)
      quit()
  anslist.append(next)
  loc+=next
ans=anslist[::-1]
ans = list(map(str, ans))
print(" ".join(ans))

Measured memory_bytes: 75780
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main()
{
    ll n,ans[3],x=0;
    cin>>n;
    ll a[n+2];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=n-2;i>=0;i--)
    {
       if(a[i]==a[i+1])
       {
           ans[x++]=a[i];
           if(x==2)
            break;
           i=i-1;
       }
    }
    if(x==2)
    cout<<ans[0]*ans[1]<<endl;
    else
    cout<<"0\n";
    return 0;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
#define int long long

string ito(int a,int b){
	string ans="";
	for(int i=0;i<b;i++)ans+=to_string(a);
	return ans;
}

signed main() {
	int a,b;
	cin>>a>>b;
	vector<string> V={ito(a,b),ito(b,a)};
	sort(V.begin(),V.end());
	cout<<V[0]<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final Scanner  SC = new Scanner(System.in);
    private static final int P = SC.nextInt();
    private static final int Q = SC.nextInt();
    private static final int R = SC.nextInt();
    
    public static void main(String[] args) {
        int min = P+Q+R;
        int[] p = {P+Q,Q+R,R+P};
        for(int i:p){
            min = Math.min(min,i);
        }
        System.out.println(min);
    }
}

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

using namespace std;

typedef long long ll;

const int MAXN = 2031;
const int INF = 1e9;

int dp[3031][3031][2];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, t; cin >> n >> t;
    vector<pair<int, int>> p(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i].first >> p[i].second;
    }
    for (int i = 0; i < MAXN; i++)
    {
        for (int j = 0; j < MAXN; j++)
        {
            dp[i][j][0] = dp[i][j][1] = -INF;
        }
    }
    dp[0][0][0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < t; j++)
        {
            dp[i][j][0] = max(dp[i - 1][j][0], (j - p[i].first >= 0) ? (dp[i - 1][j - p[i].first][0] + p[i].second) : -INF);
            dp[i][j][1] = max({dp[i - 1][j][1], (j - p[i].first >= 0) ? (dp[i - 1][j - p[i].first][1] + p[i].second) : -INF,
                    dp[i - 1][j][0] + p[i].second});
        }
    }
    int ans = -1;
    for (int j = 0; j < t; j++)
    {
        ans = max(ans, max(dp[n][j][0], dp[n][j][1]));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 71936
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>

#define ll long long
#define R register
#define IL inline
#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))
#define MP make_pair
#define PA pair<int,int>
#define MES(a,b) memset((a),(b),sizeof((a)))
#define MEC(a,b) memcpy((a),(b),sizeof((b)))
#define D double

using namespace std;

int n,len;
char s[1000];

IL int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}
IL void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

signed main()
{
	n=read();
	scanf("%s",s+1);
	len=strlen(s+1);
	Rf(i,1,min(n,len)) putchar(s[i]);
	if(len>n) puts("...");


    return 0;
}


Measured memory_bytes: 3764
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = -float('inf')
for i in range(N):
    s = 0
    j = i
    for k in range(K):
        j = P[j]-1
        s += C[j]
        ans = max(ans, s)
        if j==i: break
    d,m = divmod(K, k+1)
    if m==0 and d>1:
        m = k+1
        d -= 1
    s *= d
    ans = max(ans, s)
    for k in range(m):
        j = P[j]-1
        s += C[j]
        ans = max(ans, s)

print(ans)

Measured memory_bytes: 68576
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace AOJ2
{
    class Program
    {

        static void Main(string[] args)
        {
            List<long> resultList = new List<long>();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0)
                {
                    break;
                }

                List<int> list = new List<int>();

                for (int i = 0; i < n; i++)
                {
                    int input = int.Parse(Console.ReadLine());
                    list.Add(input);
                }

                list.Sort();

                long count = 0;
                long sum = 0;
                for (int j = 0; j < n - 1; j++)
                {
                    count += list[j];
                    sum += count;
                }

                resultList.Add(sum);

            }

            foreach (long a in resultList)
            {
                Console.WriteLine(a);
            }
            

        }
    }
}

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

ll divs[mx+1];

void sieve()
{
    for(ll i=1; i<=mx; i++) divs[i]=2;
    divs[1]=1;
    for(ll i=2; i<=mx; i++)
    {
        for(ll j=2*i; j<=mx; j+=i)
            divs[j]++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t,n;
    sieve();

    cin>>n;
    ll sum=0;
    for(ll  i=1; i<=n; i++)
    {
        sum+=i*divs[i];
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 81756
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int x = 0;
		int y = 0;
		for (char c : arr) {
		    if (c >= 'A' && c <= 'M') {
		        y++;
		    } else if (c >= 'N' && c <= 'Z') {
		        y--;
		    } else if (c >= 'a' && c <= 'm') {
		        x++;
		    } else {
		        x--;
		    }
		}
		StringBuilder sb = new StringBuilder();
		if (x > 0) {
		    for (int i = 0; i < x; i++) {
		        sb.append("a");
		    }
		} else {
		    for (int i = 0; i > x; i--) {
		        sb.append("z");
		    }
		}
		if (y > 0) {
		    for (int i = 0; i < y; i++) {
		        sb.append("A");
		    }
		} else {
		    for (int i = 0; i > y; i--) {
		        sb.append("Z");
		    }
		}
		System.out.println(sb.length());
		System.out.println(sb);
	}
}



Measured memory_bytes: 29688
def main():   
    a=input()
    b=input()
    c=input()

    X=[a,b,c]
    LEN=[len(a),len(b),len(c)]

    MF=[[[1]*2001 for j in range(3)] for i in range(3)]

    for i in range(3):
        for j in range(3):
            if i==j:
                continue
            for k in range(2001):
                for l in range(LEN[j]):
                    if k+l>=LEN[i]:
                        break
                    if X[i][k+l]!="?" and X[j][l]!="?" and X[i][k+l]!=X[j][l]:
                        MF[i][j][k]=0
                        break

    ANS=1000000
    for i in range(3):
        for j in range(3):
            if i==j:
                continue
            for k in range(2001):
                if MF[i][j][k]==1:
                    for l in range(2001):
                        if ANS<=max(LEN[i],LEN[j]+k,LEN[3-i-j]+k+l):
                            break
                        if MF[j][3-i-j][l]==1 and (k+l>2000 or MF[i][3-i-j][k+l]==1):
                            ANS=max(LEN[i],LEN[j]+k,LEN[3-i-j]+k+l)

    print(ANS)
main()


Measured memory_bytes: 3188
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    string S; cin >> S;
    int l = (S[0]-'0')*10 + S[1]-'0';
    int r = (S[2]-'0')*10 + S[3]-'0';

    if(l == 0 && r == 0 || (l == 0 && r > 12) || (r == 0 && l > 12)) cout << "NA" << endl;
    else if(l == 0 && (0 < r && r <= 12)) cout << "YYMM" << endl;
    else if(r == 0 && (0 < l && l <= 12)) cout << "MMYY" << endl;
    else if(r <= 12 && l <= 12) cout << "AMBIGUOUS" << endl;
    else if(l <= 12) cout << "MMYY" << endl;
    else if(r <= 12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

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

int main() {
    int n, y;
    cin >> n >> y;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n-i; j++) {
            if ((y-10000*i-5000*j) >= 0 && (y-10000*i-5000*j)/1000 == n-i-j) {
                printf("%d %d %d\n", i, j, n-i-j);
                return 0;
            }
        }
    }
    printf("%d %d %d\n", -1, -1, -1);
}

Measured memory_bytes: 256
import numpy as np
import sys 

readline = sys.stdin.readline 

N = int(input())
A = np.array(readline().split(), np.int64)
all_xor = 0
for a in A:
    all_xor = all_xor^a

for a in A:
    xor = all_xor^a
    print(xor, end = ' ')

Measured memory_bytes: 52000