akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll A[200200];
    ll sum[200200];
    reps(i,1,N) cin >> A[i];
    sum[0] = 0;
    reps(i,1,N){
        sum[i] = sum[i-1] + A[i];
    }

    ll ans = 0;

    reps(i,1,N){
        ll tmp = (sum[N] - sum[i]) % MOD * A[i];
        ans = (ans + tmp) % MOD;
    }

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

Measured memory_bytes: 6780
#include<iostream>
#include<string>
#pragma warning(disable:4996)
using namespace std;

int main(){
	string s1,s2;
	int n, cnt = 0;

	cin >> s1;
	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> s2;
		s2 += s2;
		for (int j = 0; j < s2.size() / 2; j++){
			if (s2.substr(j, s1.size()) == s1){
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1216
n = int(input())


def calc():
    for y in range(1, 3501):
        for z in range(1, 3501):
            up = n * y * z
            dn = 4 * y * z - n * (y + z)
            if dn <= 0:
                continue
            if up % dn == 0:
                ans = [y, z, up // dn]
                return ans


ans = calc()
print(*ans, sep=" ")


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

int main() {
	bool a, b, c, d;
	a = b = c = d = false;
	string s;
	cin >> s;
	if (6 <= s.size()) a = true;
	for (int i = 0; i < s.size(); i++) {
		if('0' <= s[i] && s[i] <= '9') b = true;
	}
	for (int i = 0; i < s.size(); i++) {
		if('a' <= s[i] && s[i] <= 'z') c = true;
	}
	for (int i = 0; i < s.size(); i++) {
		if('A' <= s[i] && s[i] <= 'Z') d = true;
	}
	if (a && b && c && d) {
		cout << "VALID" << endl;
	} else {
		cout << "INVALID" << endl;
	}
}

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



struct Si{
    int a[6];
    void move(char c) {
    int b;
     if (c=='N'){
         b=a[0];
         a[0]=a[1];
         a[1]=a[5];
         a[5]=a[4];
         a[4]=b;
      }
      if (c=='E'){
         b=a[0];
         a[0]=a[3];
         a[3]=a[5];
         a[5]=a[2];
         a[2]=b;
      }
      if(c=='S'){
         b=a[0];
         a[0]=a[4];
         a[4]=a[5];
         a[5]=a[1];
         a[1]=b;
      }
      if(c=='W'){
         b=a[0];
         a[0]=a[2];
         a[2]=a[5];
         a[5]=a[3];
         a[3]=b;
      }
      if (c=='R'){
         b=a[1];
         a[1]=a[2];
         a[2]=a[4];
         a[4]=a[3];
         a[3]=b;
      }
    }
int up(){return a[0];}
int front(){return a[1];}
int right(){return a[2];}
int left(){return a[3];}
};
bool same(Si k,Si j){
    for(int i=0;i<6;i++) if(k.a[i]!=j.a[i]) return false;
    return true;
}
int main()
{  Si r[100];
   int n;cin>>n;
     for (int j=0;j<n;j++){
         for(int i=0;i<6;i++){
         cin>>r[j].a[i];
         }
     }
     bool f2=true;
     for (int t=0;t<n-1;t++){
         for(int w=t+1;w<n;w++){
            bool f=false;
            for(int i=0;i<4;i++){
               r[w].move('R');
             for(int j=0;j<4;j++){
                r[w].move('N');
                 if(same(r[t],r[w])) f=true;
         }
     }
     r[w].move('E');
     for(int j=0;j<4;j++){
         r[w].move('N');
         if(same(r[t],r[w])) f=true;
     }
     r[w].move('W');
     r[w].move('W');
     for(int j=0;j<4;j++){
         r[w].move('N');
         if(same(r[t],r[w])) f=true;
     }
     if(f) f2=false;
         }
     }
     
   
     cout <<(f2?"Yes":"No") <<endl;
    
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  long long A, B;
  string b;
  cin >> A >> b;

  B = 0;
  for (int i = 0; i < b.length(); i++) {
    if (b[i]=='.') continue;
    int a = b[i];
    a -= '0';
    B = B*10 + a;
  }
  cout << A*B/100 << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            int[][] t = new int[h][w];
            int curPos = 0;
            int curCol = 0;
            while (curPos != h * w) {
                int row = curPos / w;
                int col = 0;

                if (row % 2 == 0)
                    col = curPos % w;
                else
                    col = w - curPos % w - 1;

                if (a[curCol] == 0)
                    curCol++;

                a[curCol]--;
                t[row][col] = curCol + 1;

                curPos++;
            }

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    out.print(t[i][j] + " ");
                }
                out.println();
            }
        }

    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                String nextLine = null;
                try {
                    nextLine = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (nextLine == null)
                    return null;
                st = new StringTokenizer(nextLine);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}
 

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;vector<int> vec;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;
		vec.push_back(x);
	}int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ans+=(vec[i-1]*vec[j-1]);
		}
	}
	cout<<ans<<endl;
 } 

Measured memory_bytes: 256
// 2011/03/15 Tazoe

#include <iostream>
using namespace std;

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

	for(int i=0; i<d; i++){
		int n;
		cin >> n;

		char spr[100][100];
		for(int j=0; j<n; j++)
			for(int k=0; k<n; k++)
				spr[j][k] = ' ';

		int a = 0;
		int b = n+1;
		for(int j=b-2; j>=a; j--)
			spr[j][a] = '#';
		while(true){
			b -= 2;
			if(a>b)
				break;

			for(int k=a; k<=b; k++)
				spr[a][k] = '#';

			if(b-a<=1)
				break;

			for(int j=a; j<=b; j++)
				spr[j][b] = '#';

			a += 2;
			if(a>b)
				break;

			for(int k=b; k>=a; k--)
				spr[b][k] = '#';

			if(b-a<=1)
				break;

			for(int j=b; j>=a; j--)
				spr[j][a] = '#';

		}

		if(i!=0)
			cout << endl;
		for(int j=0; j<n; j++){
			for(int k=0; k<n; k++){
				cout << spr[j][k];
			}
			cout << endl;
		}
	}

	return 0;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m; assert(b>=0); for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a[300];

signed main() {
	while (1) {
		cin >> n;
		if (n==0) break;
		rep(i,n) cin >> a[i];
		// dp[l][r]: 区間[l,r]から取り除けるブロックの最大個数
		int dp[303][303] = {};
		repst(w,1,n) rep(l,n) {
			int r = l+w;
			if (n<=r) break;
			if (dp[l+1][r-1]==w-1 && abs(a[l]-a[r])<=1) dp[l][r] = w+1;
			reps(i,l,r) chmax(dp[l][r], dp[l][i]+dp[i+1][r]);
		}
		cout << dp[0][n-1] << ln;
	}
}


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

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

Measured memory_bytes: 256
N = input()
ans = 'Yes'
n0 = N[0]
count = 0
if N[0] == N[1]:
    count = count + 1
if N[1] == N[2]:
    count = count + 1
if N[0] == N[2]:
    count = count + 1
if count == 3:
    ans = 'No'
print(ans)

Measured memory_bytes: 3060
int card[4][14];

int main (int argc,const char * argv[]){
    int n,i,j;
    char a;
    
    scanf("%d",&n);
    
    
    for(i = 0;i < n;i++){
        scanf(" %c %d",&a,&j);
        if(a == 'S')
            card[0][j] = 1;
        else if(a == 'H')
            card[1][j] = 1;
        else if(a == 'C')
            card[2][j] = 1;
        else
            card[3][j] = 1;
    }
    for(i = 0;i < 4;i++){
        if(i == 0)
            a = 'S';
        else if(i == 1)
            a = 'H';
        else if(i == 2)
            a = 'C';
        else
            a = 'D';
        
        for(j = 1;j <= 13;j++)
            if(card[i][j] == 0)
                printf("%c %d\n",a,j);
    }
    
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int A,B;
	char op;
	cin>>A>>op>>B;
	if(op=='+') printf("%d\n",A+B);
	else printf("%d\n",A-B);
 return 0; 
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int sum = A+B;
		if(C<=sum){
			System.out.println("Yes");
}else{
	System.out.println("No");
}
	}

}


Measured memory_bytes: 21844
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);

            System.out.println(
                A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0 ?
                    "Possible" : "Impossible");
        }
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
    using namespace std;
    int main () {
      string S;
      cin>>S;
      int count=0;
      for(int i=0;i<4;i++){
        if(S[i]==S[i+1]){
          count++;
        }
      }
       if(count>0){
         cout<<"Bad"<<endl;
       }
      else{
         cout<<"Good"<<endl;
      }
    }

Measured memory_bytes: 256
N, M = map(int, input().split())
cnt = [0 for i in range(N + 1)] 
check = []
ans = []

for i in range(M):
    p, y = map(int, input().split())
    check.append((y, p, i))

check.sort()

for y, p, i in check:
    cnt[p] += 1
    ans.append((i,str(p).zfill(6)+str(cnt[p]).zfill(6)))

ans.sort()

for aa, bb in ans:
    print(bb)

Measured memory_bytes: 36392
#include <cstdio>

using namespace std;

int h, w, n;
int a[11111];
int res[111][111];

int main(void) {
  scanf("%d%d%d", &h, &w, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a+i);
  }
  int p = 0, c = 0;
  for (int i = 0; i < h; i++) {
    if (i%2 == 0) {
      for (int j = 0; j < w; j++) {
        int x;
        if (c++ < a[p]) x = p+1;
        else {
          c = 1;
          x = ++p + 1;
        }
        res[i][j] = x;
      }
    }
    if (i%2 == 1) {
      for (int j = w-1; j >= 0; j--) {
        int x;
        if (c++ < a[p]) x = p+1;
        else {
          c = 1;
          x = ++p + 1;
        }
        res[i][j] = x;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) printf("%d%c", res[i][j], j == w-1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> a(H);
    for (int i=0; i<H; ++i) cin >> a[i];

    int si = -1, sj = -1;
    for (int i=0; i<H; ++i) {
        for (int j=0; j<W; ++j) {
            if (a[i][j] == 'S') {
                si = i, sj = j;
                break;
            }
        }
        if (si != -1) break;
    }

    using T = pair<int, int>;
    vector<vector<T>> dis(H, vector<T>(W, make_pair(INF, INF)));
    queue<pair<T, int>> que;
    dis[si][sj] = make_pair(1, -K);
    que.push(make_pair(dis[si][sj], si*W+sj));
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        int c = p.first.first, r = p.first.second, cx = p.second / W, cy = p.second % W;
        if (dis[cx][cy] < p.first) continue;
        for (int i=0; i<4; ++i) {
            int nx = cx + dx[i], ny = cy + dy[i];
            if (nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
            T n;
            if (r == 0) {
                n = make_pair(c+1, -K+1);
            } else if (c == 1) {
                if (a[nx][ny] == '#') {
                    n = make_pair(c+1, -K+1);
                } else {
                    n = make_pair(c, r+1);
                }
            } else {
                n = make_pair(c, r+1);
            }
            if (n < dis[nx][ny]) {
                dis[nx][ny] = n;
                que.push(make_pair(n, nx*W+ny));
            }
        }
    }

    int res = INF;
    for (int i=0; i<H; ++i) {
        chmin(res, dis[i][0].first);
        chmin(res, dis[i][W-1].first);
    }
    for (int i=0; i<W; ++i) {
        chmin(res, dis[0][i].first);
        chmin(res, dis[H-1][i].first);
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 9684
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 5e2+5;

int n;
int m;
int q;
multiset < int > st[N];
vector < int > stbv[N];

int main(){
    scanf("%d%d%d" , &n , &m , &q);
    for(int i = 1; i <= m; i++){
        int l , r;
        scanf("%d%d" , &l , &r);
        st[l].insert(r);
    }
    for(int i = 1; i <= n; i++){
        for(auto v : st[i]){
            stbv[i].push_back(v);
        }
    }
    while(q--){
        int a , b;
        scanf("%d%d" , &a , &b);
        int cnt = 0;
        for(int i = a; i <= b; i++){
            cnt += upper_bound(stbv[i].begin() , stbv[i].end() , b) - stbv[i].begin();
        }
        printf("%d\n" , cnt);
    }

}


Measured memory_bytes: 11520
#include <cstdio>
#include <algorithm>
#include <vector>

typedef long long LL;
const int Mod = 1000000007;
const int MN = 200005;

inline int qPow(int b, int e) {
	int a = 1;
	for (; e; e >>= 1, b = (LL)b * b % Mod)
		if (e & 1) a = (LL)a * b % Mod;
	return a;
}

int Fac[MN], iFac[MN];
inline void Init(int N) {
	Fac[0] = 1;
	for (int i = 1; i <= N; ++i) Fac[i] = (LL)Fac[i - 1] * i % Mod;
	iFac[N] = qPow(Fac[N], Mod - 2);
	for (int i = N; i >= 1; --i) iFac[i - 1] = (LL)iFac[i] * i % Mod;
}

int N, X, Y, p1, p2, C;
std::vector<int> V[MN], G[MN];
int index[MN], col[MN];
inline void Ins(int x, int y) {
	G[x].push_back(y);
	G[y].push_back(x);
}

int vis[MN], buk[MN], stk[MN], tp;
void DFS(int u) {
	vis[u] = 1, ++buk[col[u]], stk[++tp] = u;
	for (int v : G[u]) if (!vis[v]) DFS(v);
}

int main() {
	scanf("%d%d%d", &N, &X, &Y);
	Init(N);
	for (int i = 1, x, y; i <= N; ++i) {
		scanf("%d%d", &x, &y);
		V[x].push_back(y);
	}
	for (int i = 1; i <= N; ++i) if (!V[i].empty()) {
		std::sort(V[i].begin(), V[i].end());
		if (!p1) p1 = i;
		else {
			if (!p2 || V[p2][0] > V[i][0]) p2 = i;
			if (V[p1][0] > V[p2][0]) std::swap(p1, p2);
		}
		int s = V[i].size();
		index[i] = C += s;
		for (int j = 0; j < s; ++j) col[C - j] = i;
	}
	for (int i = 1; i <= N; ++i) if (!V[i].empty()) {
		int s = V[i].size(), c = index[i];
		for (int j = 1; j < s && V[i][0] + V[i][j] <= X; ++j) Ins(c, c - j);
		if (p1 && i != p1)
			for (int j = 0; j < s && V[p1][0] + V[i][j] <= Y; ++j) Ins(index[p1], c - j);
		if (p2 && i == p1)
			for (int j = 1; j < s && V[p2][0] + V[i][j] <= Y; ++j) Ins(index[p2], c - j);
	}
	int Ans = 1;
	for (int i = 1; i <= N; ++i) if (!vis[i]) {
		DFS(i);
		int s = 0;
		for (int x = 0; tp; --tp) if (buk[x = col[stk[tp]]])
			s += buk[x], Ans = (LL)Ans * iFac[buk[x]] % Mod, buk[x] = 0;
		Ans = (LL)Ans * Fac[s] % Mod;
	}
	printf("%d\n", Ans);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[100010];

bool dfs(){
  ll cnte=0,cnto=0,oidx=-1;
  rep(i,n){
    if(a[i]%2==0)cnte++;
    else{
      cnto++;
      oidx=i;
    }
  }
  if(cnte%2==1){
    return true;
  }else{
    if(cnto==1&&a[oidx]>1){
      a[oidx]--;
      ll g=0;
      rep(i,n)g=__gcd(g,a[i]);
      rep(i,n)a[i]/=g;
      return !dfs();
    }else{
      return false;
    }
  }
}

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  cout<<(dfs()?"First":"Second")<<endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v;
    int diff = 0;
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        v.push_back(a);
        if(a != i){
            diff++;
        }
    }
    if(diff == 0 | diff == 2){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const double EPS = 1e-8;
typedef complex<double> P;

int next_flag(P &now, P &d, vector<P> &ps, vector<bool> &used){
  int res = 0;
  double a = 400.0;
  REP(i, ps.size()){
    if(used[i]) continue;
    int ty = ps[i].imag() - now.imag();
    int tx = ps[i].real() - now.real();
    int ny = now.imag() - d.imag();
    int nx = now.real() - d.real();
    double tmpa = atan2(tx * ny - nx * ty, tx * nx + ty * ny);
    if(tmpa < a || (abs(tmpa - a) < EPS && abs(now - ps[i]) < abs(now - ps[res]))){
      res = i;
      a = tmpa;
    }
  }
  return res;
}

int main() {
  int N;
  while(cin >>N && N){
    vector<P> ps(N);
    REP(i, N){
      int x, y; cin >>x >>y;
      ps[i] = P(x, y);
    }
    vector<bool> used(N, 0);
    P now = P(0, 0), d = P(1, 0);
    double res = 0.0;
    REP(n, N){
      int next = next_flag(now, d, ps, used);
      used[next] = 1;
      res += abs(now - ps[next]);
      d = now;
      now = ps[next];
    }
    printf("%.1lf\n", res);
  }
  return 0;
}

Measured memory_bytes: 1320
#include <cstdio>

int main(){
	int a,b;
	while(scanf("%d %d", &a, &b)){
		if(a == 0 and b == 0) break;
		b -= a;
		int sen = 0, ghy = 0, hya = 0;
		while(b >= 1000){
			b -= 1000;
			sen++;
		}
		while(b >= 500){
			b -= 500;
			ghy++;
		}
		while(b >= 100){
			b -= 100;
			hya++;
		}
		printf("%d %d %d\n", hya, ghy, sen);
	}
	return 0;
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef long long ll;

const ll MAX = 2e6 + 5;

int n,k,h[MAX],ans = 0,t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>k;
	REP(i,n){
		cin>>h[i];
	}
	sort(h, h+n);
	t = n;
	REP(i,n){
		if(h[i] >= k){
			t = i;
			break;
		}
	}
	ans = n - t;
	cout<<ans;
	return 0;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class BCardGameForTwo {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n;
        in>>n;
        vector<ll> a(n);
        rep(i,n){
            in>>a[i];
        }
        sort(all(a));
        reverse(all(a));
        ll alice=0,bob=0;
        rep(i,n){
            if(i%2==0) alice+=a[i];
            else bob+=a[i];
        }
        out<<alice-bob<<endl;
	}
};


int main() {
	BCardGameForTwo solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 632
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char *argv[]) {
  std::string s;
  std::cin >> s;
  if (s.find("AC") != std::string::npos)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, raw_input().split())

def solve(n, m):
    dp = [0] * (n + 1)
    ai = 0
    a = -1
    dp[0] = 1
    if ai < m:
        a = int(raw_input())
    if a == 1:
        ai += 1
        if ai < m:
            a = int(raw_input())
        dp[1] = -1
    else:
        dp[1] = 1

    for i in range(2, n+1):
        if i == a:
            ai += 1
            if ai < m:
                a = int(raw_input())
            dp[i] = -1
        else:
            if dp[i-2] != -1:
                dp[i] = dp[i-2]
            if dp[i-1] != -1:
                dp[i] += dp[i-1]
    return dp[n] % (10**9+7)
print solve(n, m)

Measured memory_bytes: 462852
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000
#define vll vector<ll>
using namespace std;
const int N=100005;
ll a[N];
void solve()
{
	ll n,i,cnt=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]!=i)
			cnt++;
	}
	if(cnt<=2)
		cout<<"YES";
	else
		cout<<"NO";
	
}
 
int main() {
    
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
 
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int m; cin >> m;
    ll digit, cnt, all = 0;
    while (m--) {
        cin >> digit >> cnt;
        all += 9 * cnt + cnt * digit;
    }
    cout << (all - 10) / 9 << '\n';
    return 0;
}

Measured memory_bytes: 256
s = input()
mae = int(s[:2])
ato = int(s[2::])

ans = "NA"
if (mae == 0 and ato > 12) or (mae > 12 and ato == 0) or (mae > 12 and ato > 12) or (mae == 0 and ato == 0):
    ans = "NA"
elif mae > 12 or mae == 0:
    ans = "YYMM"
elif ato > 12 or ato == 0:
    ans = "MMYY"
else:
    ans = "AMBIGUOUS"
print(ans)



Measured memory_bytes: 38256
#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())
#define rsort(v) sort(all(v)); reverse(all(v))

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 r = 1; 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, A, B, C, D;
  string S;
  cin >> N >> A >> B >> C >> D >> S;
  A--, B--, C--, D--;
  auto check = [&](int x, int y) {
    x++, y -= 2;
    for (int i = x; i <= y; i++) {
      if (S.substr(i, 2) == "##") return false;
    }
    return true;
  };
  if (C < D) {
    if (check(A, C) && check(B, D)) yes(); no();
  }
  bool f = false;
  for (int i = B - 1; i <= D - 1; i++) {
    if (S.substr(i, 3) == "...") f = true;
  }
  if (!f) no();
  if (check(A, C) && check(B, D)) yes(); no();
}


Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
const int maxn=100+10;
char cmd[20];
int d;
int n;
struct Node
{
    int key;
    Node* left;
    Node* right;
};
int cnt;
Node *root=NULL;
void in_order(Node *p)
{
    if(p==NULL) return;
    in_order(p->left);
    printf(" %d",p->key);
    in_order(p->right);
}
void pre_order(Node *p)
{
    if(p==NULL) return;
    printf(" %d",p->key);
    pre_order(p->left);
    pre_order(p->right);
}
void print()
{
    in_order(root);
    printf("\n");
    pre_order(root);
    printf("\n");
}
void post_delete(Node *p)
{
    if(p==NULL) return;
    post_delete(p->left);
    post_delete(p->right);
    free(p);
}
bool fnd(int k)
{
    if(!root) return false;
    Node *p=root;
    while(p)
    {
        if(p->key==k) return true;
        else if(k<p->key)
        {
            p=p->left;
        }
        else p=p->right;
    }
    return false;
}
void insert(int k)
{
    Node * node=(Node *)malloc(sizeof(Node));
    node->key=k;
    node->left=NULL;
    node->right=NULL;

    Node *p=NULL;
    Node *q=root;
    while(q!=NULL)
    {
        p=q;
        if(p->key>k)
        {
            q=q->left;
        }
        else q=q->right;
    }
    if(p==NULL)
    {
        root=node;
    }
    else if(p->key>k)
    {
        p->left=node;
    }
    else p->right=node;

}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {

        scanf("%s",cmd);
        switch(cmd[0])
        {
        case 'i':
        {
            scanf("%d",&d);
            insert(d);
            break;
        }
         case 'f':
        {
            scanf("%d",&d);
            printf("%s\n",fnd(d)?"yes":"no");
            break;
        }
        case 'p':
        {
            print();
            break;

        }
        }
    }
    post_delete(root);
    return 0;
}

Measured memory_bytes: 15624
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


typedef vector<ll> V;
typedef vector<V> MATRIX;

int SIZE;
int base[40],work[40],next_loc[40];

MATRIX calc(MATRIX left,MATRIX right){

	MATRIX ret(SIZE,V(SIZE));

	for(int i = 0; i < SIZE; i++){
		for(int k = 0; k < SIZE; k++)ret[i][k] = 0;
	}

	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++){
			for(int a = 0; a < SIZE; a++){
				ret[row][col] += left[row][a]*right[a][col]%MOD;
				ret[row][col] %= MOD;
			}
		}
	}

	return ret;
}


MATRIX pow(MATRIX MULT,int count){

	MATRIX ret(SIZE,V(SIZE));

	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++){
			if(row == col)ret[row][col] = 1;
			else{
				ret[row][col] = 0;
			}
		}
	}

	while(count > 0){
		if(count%2 == 1)ret = calc(ret,MULT);
		MULT = calc(MULT,MULT);
		count /= 2;
	}

	return ret;
}


int main(){

	int N,K,C,T;
	scanf("%d %d %d %d",&N,&K,&C,&T);
	C--;

	for(int i = 0; i < N; i++)base[i] = i;

	SIZE = 5*N;

	MATRIX MULT(SIZE,V(SIZE));
	for(int row = 0; row < SIZE; row++){
		for(int col = 0; col < SIZE; col++)MULT[row][col] = 0;
	}

	int from,num,add_time;
	int work_index,base_row = 0,base_col;

	for(int loop = 0; loop < K; loop++){
		scanf("%d %d %d",&from,&num,&add_time);
		from--;

		work_index = 0;
		for(int i = 0;i < num; i++){
			work[work_index++] = base[from+i];
		}

		for(int i = 0; i < N; i++){
			if(i >= from && i <= from+num-1)continue;
			work[work_index++] = base[i];
		}

		base_col = N*(add_time-1);
		for(int i = 0; i < N; i++){
			MULT[base_row+work[i]][base_col+i]++;
		}
	}

	for(base_row = N; base_row <= 4*N; base_row += N){
		for(base_col = 0; base_col <= 4*N; base_col += N){
			if(base_row-N != base_col)continue;
			for(int i = 0; i < N; i++)MULT[base_row+i][base_col+i] = 1;
		}
	}

	MULT = pow(MULT,T);

	printf("%lld\n",MULT[C][0]%MOD);

	return 0;
}



Measured memory_bytes: 4876
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

n, q = map(int, input().split())
vals = [0] * n
node_idxes = [[] for _ in range(n)]

for i in range(n - 1):
	a, b = map(int, input().split())
	node_idxes[a - 1].append(b - 1)
	node_idxes[b - 1].append(a - 1)

for i in range(q):
	p, x = map(int, input().split())
	vals[p - 1] += x

def dfs(chi_idx, parent):
	for child in node_idxes[chi_idx]:
		if child == parent:
			continue
		vals[child] += vals[chi_idx]
		dfs(child, chi_idx)

dfs(0, -1)
print(*vals)


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

#define PI 3.141592653589793

int main(void){
    double s,d,rad=0;
    double sumx=0,sumy=0;
    
    while(scanf("%lf,%lf",&s,&d),s!=0 || d!=0){
        sumx+=s*sin(rad);
        sumy+=s*cos(rad);
        rad+=d*PI/180;
    }
    printf("%d\n%d\n",(int)sumx,(int)sumy);
    
    return 0;
}



Measured memory_bytes: 2124
#include <iostream>

int main() {
  int a, b, c, k;
  std::cin >> a >> b >> c >> k;
  while(k--) {
    if (b>=c) {
      c *= 2;
    }
    else if (a>=b) {
      b *= 2;
    }
    
  }
  if (a < b && b < c) {
    std::cout << "Yes";
  }
  else {
    std::cout << "No";
  }
}

Measured memory_bytes: 3568
K = int(input())
Ans = -1

if K % 2 == 0 or K % 5 == 0:
#解なしのため何もしない
  pass
  
elif 7 % K == 0:
  Ans = 1
  
else:
  pre_modK = 7 % K
  for i in range(2,K+1):
    modK = pre_modK * 10 + 7
    if modK % K == 0:
      Ans = i
      break
    else:
      pre_modK = modK % K

print(Ans)
  

Measured memory_bytes: 9180
import sys
from collections import Counter
lim = 998244353
N=int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    sys.exit()
E = D[1:]
d = dict(Counter(E))
sum_=1
temp=1
max_n=max(d.keys())
if len(d) ==1:
    if list(d.keys()) == [0]:
        print(0)
        sys.exit()
if 0 in d.keys():
    print(0)
    sys.exit()
for i in range(1,max_n+1):
    try:
        add = (temp ** d[i]) % lim
        sum_ = (sum_ * add) % lim
        temp = d[i]
    except:
        print(0)
        sys.exit()
print(sum_)

Measured memory_bytes: 23772
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input().rstrip()

    if S == 'ABC':
        res = 'ARC'
    else:
        res = 'ABC'

    print(res)



main()


Measured memory_bytes: 9092
#include <iostream>
#include <vector>
using namespace std;
#define ll long long

vector <ll> vec;

void findDuplicate(string s, ll n){
	ll counter = 0;
  	ll left = 0, right = 0; 

	while(left < s.size()){
		while(right < s.size() && s[right] == s[right+1])
			right++; 
		vec.push_back(right - left + 1);
		left = right + 1; 
		right = left; 
  	}
}

void solve(string s, ll n){
	ll answer = 0; 
	for(ll i = 0; i < vec.size(); i++){ 
	    answer += vec[i] / 2; 
	}

  if(vec[0] == s.size()){
	   cout << (s.size()*n) / 2 << endl; 
	   exit(0);
	 }

	if(vec[0] % 2 == 1 && vec.back() % 2 == 1 && s[0] == s[s.size() - 1]){
		cout << n * answer + n - 1 << endl; 
		exit(0);
	}
	cout << n * answer << endl; 
}

int main(){
	string s;
	ll n;

	cin >> s >> n; 

  	findDuplicate(s , n);
	solve(s , n);
}

// First, last letter are same, if odd occurence increase answer by n-1


Measured memory_bytes: 3180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	
	static int N;
	static int[] values, cant, sum, minSum;
	static List<Integer>[] adj;
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		N = sc.nextInt();
		char[] S = sc.next().toCharArray();
		values = new int[N];
		cant = new int[N];
		sum = new int[N];
		minSum = new int[N];
		for (int i = 0; i < N; i++) {
			values[i] = S[i] - '0';
		}
		adj= new List[N];
		for (int i = 0; i < N; i++) {
			adj[i] = new ArrayList<>();
		}
		for (int i = 0; i < N - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			adj[a].add(b);
			adj[b].add(a);
		}
		
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			calc(i, -1);
			ans = Math.min(ans, min(i));
		}
		if (ans == Integer.MAX_VALUE) ans = -1;
		out.println(ans);
		
		out.flush();
	}
	
	static void calc(int node, int parent) {
		cant[node] = values[node];
		sum[node] = minSum[node] = 0;
		int worst = 0;
		for (int neigh : adj[node]) if (neigh != parent) {
			calc(neigh, node);
			cant[node] += cant[neigh];
			sum[node] += sum[neigh] + cant[neigh];
			worst = Math.max(worst, minSum[neigh] + sum[neigh] + 2 * cant[neigh]);
		}
		if (worst > sum[node]) minSum[node] = worst - sum[node];
	}
	
	static int min(int node) {
		if (sum[node] % 2 == 1 || minSum[node] > 0) return Integer.MAX_VALUE;
		return sum[node] / 2;
	}
	
	
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  int ans = 0;
  int zantei = 0;
  
  rep(i, N-1){
    if(H[i] >= H[i+1]){
      zantei++;
      if(ans < zantei) ans = zantei;
    }else{
      if(ans < zantei) ans = zantei;
      zantei = 0;
    }
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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 int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N,K;
  cin>>N>>K;
  ll ans=0;
  FOR(b,1,N+1){
    //a%b>=Kなるものを求める
    ans+=N/b*max((b-K),0ll);
    ans+=max(N%b-K+1,0ll);
  }
  if(K==0)ans-=N;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def main():
    num = input()
    a, b, c, d = [int(i) for i in num]
    num_list = [a, b, c, d]
    if (a-b-c-d == 7): print('{}-{}-{}-{}=7'.format(*num_list))
    elif (a-b-c+d == 7): print('{}-{}-{}+{}=7'.format(*num_list))
    elif (a-b+c-d == 7): print('{}-{}+{}-{}=7'.format(*num_list))
    elif (a+b-c-d == 7): print('{}+{}-{}-{}=7'.format(*num_list))
    elif (a-b+c+d == 7): print('{}-{}+{}+{}=7'.format(*num_list))
    elif (a+b+c-d == 7): print('{}+{}+{}-{}=7'.format(*num_list))
    elif (a+b-c+d == 7): print('{}+{}-{}+{}=7'.format(*num_list))
    elif (a+b+c+d == 7): print('{}+{}+{}+{}=7'.format(*num_list))
                    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
      #define ll  long long int
      #define N 100000
      #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
      #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
      #define po pop_back
      #define pb push_back
      #define pp pair<ll,ll>
      #define lb lower_bound
      #define fi first
      #define se second
      #define debug(x) cout << #x << " = " << x << endl
      #define ub upper_bound
      #define ibs ios_base::sync_with_stdio(false)
      #define cti cin.tie(0)
      #define all(x) x.begin(),x.end()
      #define PI 3.14159265
      #define cot cout.tie(0)
      using namespace std;
       /**
        * @author :: Sawlani
        *
        */
        int main()
        {
             ll a,b;
             cin >>  a >>  b;
             if(2*b>=a)
                    cout << 0 <<  endl;
             else
                cout <<  a-2*b << endl;

        }


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! { n: usize }
    let list = vec![7,5,3];
    println!("{}", if list.contains(&n) { "YES" } else { "NO" });
}


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

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

    int sum{0};

    for(int i{1}; i<=N; ++i){
        if( i/10000+(i/1000)%10+(i/100)%10+(i/10)%10+i%10>=A and
            i/10000+(i/1000)%10+(i/100)%10+(i/10)%10+i%10<=B){
            sum += i;
        }
    }

    cout << sum << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){int N;
cin>>N;ll a[N];REP(i,N)cin>>a[i];
SORT(a,N);int j=N-1;
while(1){if(a[j]==a[j-1]||j==1)break;j--;}
int k=j-2;while(1){if(a[k]==a[k-1]||k==0)break;k--;}
if(j==1)cout<<0<<endl;
else cout<<a[j]*a[k]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

int main(){
  int N,M,D,R;
  cin >>N>>M;
  int MIN=100000;
  int MAX=0;
  for (int i=0;i<M;i++){
    cin >>D>>R;
    MAX=max(MAX,D);
    MIN=min(MIN,R);
  }
  int ans=MIN-MAX+1;
  if (ans>=1){
    cout <<ans<< endl;
  }else{
    cout <<0;
  }  
}  

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

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

#define pb push_back

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	ll mx = 0, ans = 0;
	while (n--) {
		ll x;
		cin >> x;
		if (x < mx) ans += mx - x;
		mx = max(mx, x);
	}
	cout << ans;
   return 0;
}

Measured memory_bytes: 3640