akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	ll n ; cin >> n ;
	vvll g(n,vll(0)) ;
	for(int i=0;i<n;i++){
		ll a,b ;
		cin >> a >> b ;
		for(int j=0;j<b;j++){
			ll c ; cin >> c ;
			c-- ;
			g.at(i).emplace_back(c) ;
		}
	}
	vll d(n,INF) ;
	d.at(0) = 0 ;
	queue<ll> q ;
	q.push(0) ;
	while(!q.empty()){
		ll p = q.front() ;
		q.pop() ;
		for(int i=0;i<g.at(p).size();i++){
			if(d.at(g.at(p).at(i))>d.at(p)+1){
				d.at(g.at(p).at(i)) = d.at(p)+1 ;
				q.push(g.at(p).at(i)) ;
			}
		}
	}
	for(int i=0;i<n;i++) cout << i+1 << " " << (d.at(i)==INF?-1:d.at(i)) << endl ;
}



Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

int s, t, x, y;

int main() {
    cin >> s >> t >> x >> y;
    x -= s; y -= t;
//    1回目の往路
    for (int i = 0; i < x; i++) {
        cout << 'R';
    }
    for (int i = 0; i < y; i++) {
        cout << 'U';
    }
//     1回目の復路
    for (int i = 0; i < x; i++) {
        cout << 'L';
    }
    for (int i = 0; i < y; i++) {
        cout << 'D';
    }
    //    2回目の往路
    cout << 'D';
    for (int i = 0; i < x + 1; i++) {
        cout << 'R';
    }
    for (int i = 0; i < y + 1; i++) {
        cout << 'U';
    }
    cout << 'L';
    //     2回目の復路
    cout << 'U';
    for (int i = 0; i < x + 1; i++) {
        cout << 'L';
    }
    for (int i = 0; i < y + 1; i++) {
        cout << 'D';
    }
    cout << 'R' << endl;
}





Measured memory_bytes: 256
def battle(first, second):
    if first > second:
        return first - second
    elif first < second:
        return second - first
    else:
        return first

n = 1 << int(input())
a = []
for i in range(n):
    a.append(int(input()))
while True:
    if n // 2 == 0:
        break
    new = []
    for i in range(n // 2):
        new.append(battle(a[i*2], a[i*2+1]))
    a = new
    n //= 2
print(a[0])

Measured memory_bytes: 18664
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int n, k;
	int x, y, z;
	scanf("%d %d %d", &x,&y,&z);
	n = max(max(x, y), z);
	k = min(min(x, y), z);
	printf("%d\n", n - k);


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int n,k;string s;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> k >> s;
    s[k-1] = s[k-1]-'A'+'a';
    cout << s << el;
    return 0;
}

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

int main(void){
  int i,len1,len2;
    
  char str1[256];
  char str2[256];
  scanf("%s",str1);
  scanf("%s",str2);
  
  len1=strlen(str1);
  len2=strlen(str2);
  
  for(i=0;i<len1;i++){
    if(str1[i]!=str2[i])break;
  }
  if(i==len2-1){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,l;
    cin>>n>>l;
    int left = l;
    int right = l + n - 1;
    if ( left < 0 && right < 0 ){
        int ans = 0;
        rep(i,left,right){
            ans += i;
        }
        cout<<ans<<endl;
    }
    else if ( left > 0 && right > 0 ){
        int ans = 0;
        rep(i,left+1,right+1){
            ans += i;
        }
        cout<<ans<<endl;
    }
    else{
        int ans = 0;
        rep(i,left,right+1){
            ans += i;
        }
        cout<<ans<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
int A, B;

void solve() {
	int ans;
	if ((A + B) >= 24) {
		ans = (A + B) - 24;
	}
	else {
		ans = A + B;
	}
	// 出力
	cout << ans << endl;
}

int main()
{
	// 入力
	cin >> A >> B;
	solve();
    return 0;
}

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

int main() {
string a,b,c;
cin>>a>>b>>c;
char t='a';
bool f = true;
while(f){

    switch(t){
        case 'a':
        if(a.length()==0){
            f=false;
            t='A';
        }else{
            t=a[0];
            a=a.substr(1);
        }
        break;
        case 'b':
        if(b.length()==0){
            f=false;
            t='B';
        }else{
            t=b[0];
            b=b.substr(1);
        }
        break;
        case 'c':
        if(c.length()==0){
            f=false;
            t='C';
        }else{
            t=c[0];
            c=c.substr(1);
        }
        break;
    }
    
}

cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

vector<int> kmpFailureFunc(const string& S)
{
    const int n = S.size();
    vector<int> F(n + 1, -1);
    F[1] = 0;
    for (int i = 2;i <= n; i++) {
        char c = S[i - 1];
        int l = F[i - 1];
        while (l >= 0 && S[l] != c)
            l = F[l];
        F[i] = l + 1;
    }

    return F;
}

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S, T;
    cin >> S >> T;
    const int MAXN = 2000000;
    VEC(int) Next(S.size(), -1);

    VEC(int) kmpT = kmpFailureFunc(T);

    // Scanning S*
    int suff = 0;
    FOR(i, 0, MAXN) {
        char c = S[i % S.size()];
        while (suff >= 0 && T[suff] != c)
            suff = kmpT[suff];
        suff++;
        
        if (suff == T.size()) {
            Next[(i - T.size() + 1) % S.size()] = (i + 1) % S.size();
            suff = kmpT[suff];
        }
    }

    if (*max_element(ALL(Next)) == -1) {
        cout << 0 << endl;
    } else {

        VEC(int) Seen(S.size(), -1);
        int index = 0, ret = 0;
        FOR(i, 0, S.size())
            if (Seen[i] < 0 && Next[i] >= 0) {
                int tmp = i, reps = 0;
                while (Next[tmp] >= 0) {
                    if (Seen[tmp] == index) {
                        cout << -1 << endl;
                        return 0;
                    }

                    Seen[tmp] = index;
                    tmp = Next[tmp];
                    reps++;
                }

                ret = max(ret, reps);
                index++;
            }

        cout << ret << endl;
    }
    return 0;
};


Measured memory_bytes: 7580
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

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 * b / GCD(a, b); }


int main(){
    string S; // 最初の文字列
    int Q; // クエリの数
    cin >> S >> Q;

    int cnt = 0; // 1の数
    deque<string> deq;

    deq.push_back(S);
    for (int i=0;i<Q;++i) {
        int t;
        cin >> t;
        if (t == 1) {
            cnt++; // 反転する回数
        } else {
            int f;
            string c;
            cin >> f >> c;
            if (cnt % 2 == 0) {
                if (f == 1) deq.emplace_front(c);
                else deq.emplace_back(c);
            } else {
                if (f == 2) deq.emplace_front(c);
                else deq.emplace_back(c);
            }
        }
    }

    if (cnt % 2 == 0) {
        rep(i, deq.size()) {
            cout << deq[i];
        }
        cout << endl;
        return 0;
    } else {
        for (int i=deq.size()-1;i>=0;--i) {
            if (deq[i].size() > 1) {
                for (int j=deq[i].size()-1;j>=0;--j) {
                    cout << deq[i][j];
                }
            } else {
                cout << deq[i];
            }
        }
        cout << endl;
        return 0;
    }

}

Measured memory_bytes: 11648
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int S[] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
		int H[] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
		int C[] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
		int D[] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
		String[] m = new String[n];
		int[] s = new int[n];
		for(int a =0;a<n;a++){
			m[a] = scan.next();
			s[a] = scan.nextInt();
		}
		for(int b = 0;b<n;b++){
			if(m[b].equals("S")){
				for(int c = 1;c<=13;c++){
					if(s[b] == c){
						S[c-1] = 1;
						break;
					}
				}
			}else if(m[b].equals("H")){
				for(int c = 1;c<=13;c++){
					if(s[b] == c){
						H[c-1] = 1;
						break;
					}
				}
			}else if(m[b].equals("C")){
				for(int c = 1;c<=13;c++){
					if(s[b] == c){
						C[c-1] = 1;
						break;
					}
				}
			}else if(m[b].equals("D")){
				for(int c = 1;c<=13;c++){
					if(s[b] == c){
						D[c-1] = 1;
						break;
					}
				}
			}
		}
		for(int e = 0;e<13;e++){
			if(S[e] == 0){
				System.out.println("S "+(e+1));
			}
		}
		for(int f = 0;f<13;f++){
			if(H[f] == 0){
				System.out.println("H "+(f+1));
			}
		}
		for(int g = 0;g<13;g++){
			if(C[g] == 0){
				System.out.println("C "+(g+1));
			}
		}
		for(int h = 0;h<13;h++){
			if(D[h] == 0){
				System.out.println("D "+(h+1));
			}
		}
	}
}

Measured memory_bytes: 18236
#include<iostream>
#include<map>
using namespace std;
map<string, int>mo;
int main()
{
	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		mo[s]++;
	}
	int maxn = -1;
	for (const auto& x : mo)
	{
		int v = x.second;
		if (v > maxn)maxn = v;
	}
	for (auto& p : mo)
	{
		if (p.second == maxn)cout << p.first << endl;
	 }
	
}

Measured memory_bytes: 25216
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<iomanip>
#include<cassert>
#include<complex>
#include<functional>
#include<list>
#include<cmath>
#include<stack>
#include<assert.h>
#define LL long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
using namespace std;
LL a[3333];
int main(){
  int n;
  LL ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    ans+=a[i];
  }
  ans-=n;
  cout<<ans;
  return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		string s;
		cin >> n >> s;
		int ret = 1;
		for(int i=1; i < n; i++){
			if(s[i] != s[i-1])ret++;
		}
		cout << ret << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    vector<vector<ll>> graph(n);
    for (ll i = 0; i < n - 1; i++)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<ll> cost(n, 0);
    for (ll i = 0; i < q; i++)
    {
        ll p, x;
        cin >> p >> x;
        p--;
        cost[p] += x;
    }
    vector<bool> seen(n, false);
    vector<ll> d(n, 0);
    stack<ll> st;
    st.push(0);
    d[0] = cost[0];
    while (!st.empty())
    {
        ll now = st.top();
        seen[now] = true;
        st.pop();
        for (auto v : graph[now])
        {
            if (!seen[v])
            {
                st.push(v);
                d[v] += d[now] + cost[v];
            }
        }
    }
    for (auto ans : d)
    {
        cout << ans << ' ';
    }
    cout << endl;
}


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

int main() {
    int r, c;
    cin >> r >> c;
    int matrix[r+1][c+1] = {0};
    int total = 0;
    
    for(int i = 0; i < r; i++) {
      matrix[i][c] = 0;
      for(int j = 0; j < c; j++) {
        cin >> matrix[i][j];
        total += matrix[i][j];
        matrix[i][c] += matrix[i][j];
        matrix[r][j] += matrix[i][j];
            
        cout << matrix[i][j] << " ";
      }
      cout << matrix[i][c] << endl;
    }
    matrix[r][c] = total;
    for(int j = 0; j < c; j++) {
      cout << matrix[r][j] << " ";
    }
    cout << matrix[r][c] << endl;
    
    return 0;
}


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

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::vector<std::vector<int32_t>> grid(1000 + 1,
                                         std::vector<int32_t>(1001 + 1, 0));
  for (size_t i = 0; i < N; i++) {
    std::pair<uint32_t, uint32_t> tl, br;
    std::cin >> tl.first >> tl.second >> br.first >> br.second;
    grid[tl.first][tl.second]++;
    grid[br.first][br.second]++;
    grid[br.first][tl.second]--;
    grid[tl.first][br.second]--;
  }

  for (size_t i = 0; i < grid.size(); i++) {
    for (size_t j = 1; j < grid[0].size(); j++) grid[i][j] += grid[i][j - 1];
  }
  for (size_t i = 1; i < grid.size(); i++) {
    for (size_t j = 0; j < grid[0].size(); j++) grid[i][j] += grid[i - 1][j];
  }

  uint32_t max = 0;
  for (size_t i = 0; i < grid.size(); i++) {
    for (size_t j = 0; j < grid[0].size(); j++) {
      if (max < static_cast<uint32_t>(grid[i][j])) max = grid[i][j];
    }
  }

  std::cout << max << std::endl;

  return 0;
}


Measured memory_bytes: 6844
#include <stdio.h>

int main(void){
    int a,b,sum,cnt;

    while (scanf("%d %d", &a, &b) == 2){
        cnt=0;
        sum = a+b;
        while(sum){
            cnt++;
            sum /= 10;
        }
        printf("%d\n", cnt);
    }
    return 0;
}

Measured memory_bytes: 1028
///HELLO THERE~!
///CREATED BY MD SADMAN MEHEDI SIVAN(IUT CSE[SWE'19])

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

#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define READ            freopen("input.txt","r",stdin);
#define WRITE           freopen("red.txt","w",stdout);

using ll=long long;
using ull=unsigned long long;
const double pi = 2*acos(0.0);
const long long MX = 2e5+7;

int main()
{
    FASTIO;
    long long n;
    cin>>n;
    long long a[n+1];
    ll f=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]!=i+1)
            f++;
    }
    if(f==0 || f==2)
    {
        cout<<"YES";
    }
    else
        cout<<"NO";



    return 0;



}


Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>

using namespace std;


const int MAXN=1e5+10;
using ll=long long int;

struct Node{
    int lbound,rbound;
    bool updated;
    ll diff;
    ll sum;
    Node *left,*right;
};

Node segtree[MAXN*2];
Node* next_pos=segtree;
int n,q;

Node* build(int left,int right){
    auto* cur=next_pos;
    next_pos++;
    cur->lbound=left;
    cur->rbound=right;

    cur->updated=false;
    cur->diff=0;
    

    int mid=(left+right)/2;

    //リーフノードのケース
    if (right-left==1) {
        cur->sum=0;
        return cur;
    }

    cur->left=build(left,mid);
    cur->right=build(mid,right);
    //総和を集計
    cur->sum=0;
    return cur;
}

//シングルノードの更新
void update(Node& self,ll d){
    self.diff=d;
    self.sum=d*(self.rbound-self.lbound);
    self.updated=true;
}

void update(Node& self,int l,int r,int u){
    int mid=(self.lbound+self.rbound)/2;
    
    if (self.rbound-self.lbound!=1&&self.updated){
        update(*self.left,self.diff);
        update(*self.right,self.diff);
        self.diff=0;
        self.updated=false;
    }

    if (l==self.lbound&&r==self.rbound){
        update(self,u);
    }else if (l>=mid){
        update(*self.right,l,r,u);
        self.sum=self.left->sum+self.right->sum;
    }else if (r<=mid){
        update(*self.left,l,r,u);
        self.sum=self.left->sum+self.right->sum;
    }else{
        update(*self.left,l,mid,u);
        update(*self.right,mid,r,u);
        self.sum=self.left->sum+self.right->sum;
    }
}

//シングルポイント
int query(Node& self,int i){
    // puts("q");
    if (self.rbound-self.lbound==1&&self.lbound==i) return self.diff;
    int mid=(self.lbound+self.rbound)/2;
    if (i>=mid) return query(*self.right,i)+self.diff;
    else return query(*self.left,i)+self.diff;
}

//区間
ll query(Node& self,int l,int r){
    int mid=(self.lbound+self.rbound)/2;

    //更新があるノードの区間をプッシュボタン
    if (self.rbound-self.lbound!=1&&self.updated){
        update(*self.left,self.diff);
        update(*self.right,self.diff);
        self.diff=0;
        self.updated=false;
    }

    if (l==self.lbound&&r==self.rbound){
        return self.sum;
    }else if (l>=mid){
        return query(*self.right,l,r);
    }else if (r<=mid){
        return query(*self.left,l,r);
    }else{
        return query(*self.left,l,mid)+query(*self.right,mid,r);
    }
}

int main(){
    scanf("%d%d",&n,&q);
    build(0,n);
    // printf("%lld\n",segtree[0].sum);
    for(int i=0;i<q;i++){
        int t;
        scanf("%d",&t);
        if (t==0){
            int s,t,x;
            scanf("%d%d%d",&s,&t,&x);
            update(segtree[0],s,t+1,x);
        }else{
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%lld\n",query(segtree[0],l,r+1));
        }

    }
    return 0;
}


Measured memory_bytes: 12132
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, p, pn, i;
    int[] a;

    for(;;){
      n = sc.nextInt(); p = sc.nextInt();
      if(n == 0 && p == 0)break;
      a = new int[n];
      for(i = 0;i < n;i++)a[i] = 0;
      pn = p;

      for(i = 0;;i++){
        i = i % n;
        if(p != 0){
          a[i]++; p--;
        }else{
          p += a[i]; a[i] = 0;
        }
        if(a[i] == pn)break;
      }

      out.println(i);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20440
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    n, w = LI()
    weight = [0 for _ in range(n+1)]
    value = [0 for _ in range(n+1)]

    for i in range(1,n+1):
        weight[i], value[i] = LI()


    dp = [[float("inf") for _ in range(sum(value)+1)]  for _ in range(n+1)]
    dp[0][0] = 0
    for i in range(n):
        for j in range(len(dp[0])):
            if j < value[i+1]:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = min(dp[i][j], dp[i][j-value[i+1]] + weight[i+1])

    ans = 0
    for i in range(len(dp[n])):
        if dp[n][i] <= w:
            ans = i
    
    print(ans)
main()


Measured memory_bytes: 261404
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
const ll LONG_INF = 1e18 + 10;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e5 + 10;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
        cin >> n;
        vector <int> a(n);
        for(int& i : a){
                cin >> i;
        }
        sort(a.begin(), a.end());
        ll ans = 0;
        wis(a);
        for(int i = 0; i < n; i++){
                for(int j = i + 1; j < n; j++){
                        for(int q = j + 1; q < n; q++){
                                if(a[i] + a[j] > a[q] && set<int>{a[i], a[j], a[q]}.size() == 3){
                                        wis(i, j, q);
                                        ans++;
                                }
                        }

                }
        }
        cout << ans << '\n';
}


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

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

const int MOD = 1e9 + 7;
const int MX = 2e6 + 5;

// LL expo(LL a, LL x) {
// 	if(x == 0) {
// 		return 1;
// 	}
// 	LL ret = expo(a, x/2);
// 	ret = (ret * ret)%MOD;
// 	if(x%2 != 0) {
// 		ret = (ret * (a%MOD))%MOD; 
// 	}
// 	return ret;
// }

LL expo(LL a, LL x) {
	LL ret = 1;
	while(x > 0) {
		if(x & 1) {
			ret = (ret * a)%MOD;
		}
		a = (a * a)%MOD;
		x = x >> 1;
	}
	return ret;
}

LL fact[MX], ifact[MX];
void aux() {
	fact[0] = 1;
	// ifact[0] = 1;
	for(int i=1;i<MX;i++) {
		fact[i] = (fact[i-1] * i)%MOD;
		// ifact[i] = expo(fact[i], MOD-2);
	}
	ifact[MX-1] = expo(fact[MX-1], MOD-2);
	for(int i=MX-2;i>=0;i--) {
		ifact[i] = (ifact[i+1] * (i+1))%MOD;
	}
}

LL ncr(int n, int r) {
	if(r > n || r < 0) return 0;
	LL ret = ((fact[n] * ifact[n-r])%MOD * ifact[r])%MOD;
	return ret;
}

LL calc(int r, int c) {
	LL ret = 0;
	for(int i=0;i<=r;i++) {
		ret = (ret + ncr(i + 1 + c, c))%MOD;
	}
	return ret;
}

int main() {
	aux();
	int r1, r2, c1, c2;
	cin >> r1 >> c1 >> r2 >> c2;

	LL ans = 0;
	ans = (calc(r2, c2) - calc(r1 - 1, c2) + MOD - calc(r2, c1 - 1) + MOD + calc(r1 - 1, c1 - 1))%MOD;

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


Measured memory_bytes: 34800
N = int(input())
UVW = [list(map(int, input().split())) for _ in range(N-1)]

_adjacent_dict={}

for u,v,w in UVW:
  _adjacent_dict.setdefault(u, set()).add((v,w))
  _adjacent_dict.setdefault(v, set()).add((u,w))
  
c = [None]*(N+1) # 0:black, 1:white, c[i]:頂点i

stack = [1]
c[1] = 0

while stack:
  u = stack.pop()
  for v,w in _adjacent_dict[u]:
    if c[v] is None:
      c[v] = c[u]^(w%2)
      stack.append(v)

for d in c[1:]:
  print(d)
    
    


Measured memory_bytes: 74472
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 1e5+5;

int n, m, h[MM], mx[MM];

int main(){
    scan(n, m);
    for(int i = 1; i <= n; i++)
        scan(h[i]);
    for(int i = 0,a,b; i < m; i++){
        scan(a, b);
        mx[a] = max(mx[a], h[b]);
        mx[b] = max(mx[b], h[a]);
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        cnt += (h[i] > mx[i]);
    }
    print(cnt);
    
    return 0;
}

Measured memory_bytes: 4372
using System;

namespace Q1
{
    class Program
    {
        static void Main(string[] args)
        {
            String line;
            line = Console.ReadLine();
            String[] words = line.Split(' ');

            int a = int.Parse(words[0]);
            int b = int.Parse(words[1]);

            if(a+b==15)
            {
                Console.WriteLine("+");
            }
            else if (a*b==15)
            {
                Console.WriteLine("*");
            }
            else
            {
                Console.WriteLine("x");
            }

            //Console.WriteLine("");
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define maxn 500010
inline ll read()
{
    ll x=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
inline void write(ll x)
{
    static int buf[20],len; len=0;
    if(x<0)x=-x,putchar('-');
    for(;x;x/=10)buf[len++]=x%10;
    if(!len)putchar('0');
    else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int a[maxn];
int n,k;
void modify()
{
	static int b[maxn];
	for(int i=1;i<=n;i++)
		b[i]=0;
	for(int i=1;i<=n;i++){
		int l=std::max(1,i-a[i]),r=std::min(n,i+a[i]);
		++b[l]; --b[r+1];
	}
	a[0]=0;
	for(int i=1;i<=n;i++)
		a[i]=a[i-1]+b[i];
}
int main()
{
	n=read(); k=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	while(k--){
		int flag=1;
		for(int i=1;i<=n;i++)
			if(a[i]<n){
				flag=0; break;
			}
		if(flag)break;
		modify();
		// for(int i=1;i<=n;i++)
		// 	writesp(a[i]);
		// putchar('\n');
	}
	for(int i=1;i<=n;i++)
		writesp(a[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 3232
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(f64, String;n);
    println!(
        "{}",
        vs.into_iter()
            .map(|(x, u)| if u == "JPY".to_string() {
                x
            } else {
                x * 380_000.0
            })
            .sum::<f64>()
    )
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, K; cin >> n >> K;
    ll res = 1LL * n * n;
    if(K > 0){
        rep(b, 1, n + 1){
            int cur = n / b * min(b, K) - 1;
            cur += min(n % b + 1, K);
            res -= cur;
        }
    }

    cout << res << endl;

    return 0;
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        long k = sc.NextLong();

        int answer = a - b;

        if (k % 2 == 1)
        {
            answer = -1 * answer;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
ll MOD = 1000000007;
#define INF (1e9)

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll sum = a + b + c;
    cout << sum - max(a, max(b, c)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0; i < n; i++)
const int MAX = 2e3+3;
const int INF = 1e9;
const int MOD = 1e9+7;

struct W{
  int to;
  int from;
  bool operator<( const W& right ) const {
      return to < right.to;
  }
};

int main(){

  int n,m; cin >> n >> m;
  vector<W> V;
  REP(i,m){
    int l,r; cin >> l >> r;
    V.push_back( {r,l} );
  }

  sort(V.begin(),V.end());
  int now = -INF,ans = 0;
  REP(i,m){
    if(now <= V[i].from) now = V[i].to,ans++;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

bool is_pal(string t){
        string l = t;
        reverse(l.begin(), l.end());
        if (l == t)
                return true;
        return false;
}

int main(){
        string s;
        cin >> s;
        if (is_pal(s) && is_pal(s.substr(0, (s.size()) / 2)))
                cout << "Yes";
        else
                cout << "No";
}

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

int main() {
  int n;
  cin >> n;
  int t1 = 0;
  int x1 = 0;
  int y1 = 0;
  for (int i = 0; i < n; ++i) {
    int t2, x2, y2;
    cin >> t2 >> x2 >> y2;
    int d = abs(x2 - x1) + abs(y2 - y1);
    if (d > t2 - t1 || d % 2 != (t2 - t1) % 2) {
      cout << "No" << endl;
      return 0;
    }
    t1 = t2;
    x1 = x2;
    y1 = y2;
  }
  cout << "Yes" << endl;
}


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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	ll ans = 0;
	if (a.at(0) > x) {
		ans += a.at(0) - x;
		a.at(0) = x;
	}
	for (int i = 1; i < n; i++) {
		if (a.at(i) + a.at(i - 1) > x) {
			ans += a.at(i) + a.at(i - 1) - x;
			a.at(i) -= a.at(i) + a.at(i - 1) - x;
		}
	}
	cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int n; cin>>n;
        vi l(n);
        rep(i,n)cin>>l[i];
        sort(all(l),greater<int>());
        int lng=l[0];
        reverse(all(l));
        l.pop_back();
        int sum=0;
        each(it,l)sum+=it;
        if(sum>lng)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    string S; cin >> S;
    if(S.size()%2==1){
        cout << "No" << endl;
    }else {
        rep(i,SZ(S)/2){
            if(S[i*2]=='h' && S[i*2+1]=='i');
            else {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
def main():
        K, N = map(int, input().split())

        A = list(map( int, input().split() ))

        dist = []

        for i in range(N):
                if i!=N-1:
                        dist.append(A[i+1]-A[i])
                else:
                        dist.append(K-A[i]+A[0])

        ans = sum(dist)-max(dist)

        print("{}".format(ans))

if __name__=="__main__":
        main()

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

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


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

    while(1){
        int w, h;
        cin >> w >> h;

        if(w==0) break;

        vector<vector<int>> c(h, vector<int>(w));
        rep(i, h) rep(j, w) cin >> c[i][j];

        int cnt = 0;
        vector<vector<int>> seen(h, vector<int>(w, 0));

        rep(i, h) rep(j, w){
            if(c[i][j] == 0) continue;
            if(seen[i][j]) continue;
            ++cnt;
            
            seen[i][j] = cnt;
            vector<pair<int, int>> stack;
            stack.push_back(make_pair(i, j));
            while(!stack.empty()){
                int x = stack.back().second;
                int y = stack.back().first;
                stack.pop_back();

                rep(dir, 8){
                    int ny = y + dy[dir];
                    int nx = x + dx[dir];

                    if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
                    if(c[ny][nx] == 0) continue;
                    if(seen[ny][nx]) continue;

                    seen[ny][nx] = cnt;
                    stack.push_back(make_pair(ny, nx));
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3072
'use strict'

const gcd = (a, b) => {
    const r = a % b
    if(r === 0){
        return b
    }
    return gcd(b, r)
}

const main = (input) => {
    input = input.split('\n')
    const n = parseInt(input[0].split(' ')[0])
    const x = parseInt(input[0].split(' ')[1])
    const arr = input[1].split(' ').map(v => Math.abs(parseInt(v) - x)).sort((a, b) => a - b)
    console.log(arr.reduce((p, c) => gcd(p, c)))
    
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 28740
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[100005],b[100005];
    cin>>n;
    for(int i=1;i<n+1;i++)
    {
        cin>>a[i];
        b[a[i]]=i;


    }
    for(int i=1;i<n+1;i++)
    {
        cout<<b[i]<<" ";
    }


}


Measured memory_bytes: 1536
temp = list(map(int, input().split()))
N = temp[0]
K = temp[1]
Q = temp[2]
A = []
anscount = []
for i in range(N):
  anscount.append(0)
for i in range(Q):
  A.append(int(input())-1)
  anscount[A[i]] += 1
      
for i in range(N):
  if(K - Q + anscount[i] >0):
    print("Yes")
  else:
    print("No")

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

int main(){
int N;
   cin>>N;
  vector<int>A(N);
  for(int i=0; i<N; i++){ cin>>A[i];  }
  
  int max=*max_element(A.begin(), A.end());
  int min=*min_element(A.begin(), A.end());

  cout<<abs(max-min);
  
}

Measured memory_bytes: 256
#include<iostream>
#define N 6
using namespace std;
int main(){
	int m;
	cin>>m;
	for(int tc = 0; tc < m; ++tc){
		int map[N][N]={{0,},};
		int ans = 0;
		
		for(int i = 0; i < 5; ++i){
			for(int j = 0; j < 5; ++j){
				cin >> map[i][j];
			}
		}

		for(int i = 0; i < 5; ++i){
			for(int j = 0; j < 5; ++j){
				if( map[i][j] ){
					int height = 0;
					int min_width = 5;
					
					for(int k = i; k < N; ++k){
						++height;
						if( map[k][j] ){
							for(int l = j; l < N; ++l){
								if( map[k][l] == 0 ){
									min_width = min( min_width, (l-j) );
									//cout << "AREA: " << height * (l-j) << endl;
									ans = max( ans, height * min_width );
									break;
								}
							}
						}else
							break;
					}
				}
			}
		}
		
		cout << ans << endl;
	}
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n), dp(n, 1e9);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i-j < 0) break;
			dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch FiftyFifty | diff FiftyFifty.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address FiftyFifty.cpp && ./a.out

/*
 
 6/29/2019
 
 5:00-
 
 */

string S;

bool solve() {
  map<char,int> cnt;
  REP(i,SZ(S)) cnt[S[i]]++;
  if(SZ(cnt)!=2) return false;
  REP(i,SZ(S)) if(cnt[S[i]]!=2) return false;
  return true;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  cout<<(solve()?"Yes":"No")<<endl;
  
  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);
		String S = scan.nextLine();
		int N = S.length();

		if (S.substring(0, (N - 1) / 2).equals(S.substring((N + 1) / 2, N))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		scan.close();
	}
}


Measured memory_bytes: 24916
#include <iostream>
#include <algorithm>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> PII;
typedef pair<int, PII> P;
typedef vector<P> VP;
typedef vector<int> VI;

int main ( void )
{
  int n, m, a;
  while (cin >> n >> m >> a, n|m|a) {
    VP line(m);
    VI result(n);
    rep (i, n) { result[i] = i+1; }
    rep (i, m) {
      cin >> line[i].X >> line[i].Y.X >> line[i].Y.Y;
      line[i].X = -line[i].X;
    }
    sort(line.begin(), line.end());
    rep (i, m) {
      swap(result[line[i].Y.X-1], result[line[i].Y.Y-1]);
    }
    rep (i, n) if (result[i] == a) {
      cout << i+1 << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1212