akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void print3(int x, int y, int z){
	cout << x << " " << y << " " << z << endl;
}

void Main(){
	int l;
	cin >> l;
  
	// data : l の 2 進法表記した各桁 (逆向き)
	vi data;
	// cnt : data のうち 1 の数
	int cnt = 0;

	int L = l;
	while(L>0){
		data.pb(L%2);
		if(L%2) cnt++;
		L /= 2;
	}
	// for(auto d: data) cout << d;
  
	// 頂点数 n, 辺数 m
	int n = data.size();
	int m = (n-1)*2 + cnt - 1;
	cout << n << " " << m << endl;

	int temp = 1;
	rep3(i,1,n-1){
		print3(i, i+1, 0);
		print3(i, i+1, temp);
		temp *= 2;
	}

	// 最上位桁 data[n-1] は無視
	temp = 1;
	rep(i, n-1) {
		if(data[i]) {
			l -= temp;
			// cout << "debug: ";
			// print3(i, temp, l);
			print3(i+1, n, l);
		}
		temp *= 2;
	}
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

#define MAX 100000+1

struct Rectangle{ int height;  int pos; };

int N;

long long getLargestRectangle( int size, int buffer[] )
{
	stack<Rectangle> S;
	long long maxv = 0;
	buffer[size] = 0;

	for( int i = 0; i <= size; i++ ) {
		Rectangle rect;
		rect.height = buffer[i];
		rect.pos = i;
		if ( S.empty() ) {
			S.push( rect );
		} else {
			if ( S.top().height < rect.height ) {
				S.push( rect );
			} else if ( S.top().height > rect.height ) {
				int target = i;
				while ( !S.empty() && S.top().height >= rect.height ) {
					Rectangle pre = S.top(); S.pop();
					long long area = (long long)pre.height * (i - pre.pos);
					maxv = max( maxv, area );
					target = pre.pos;
				}
				rect.pos = target;
				S.push(rect);
			}
		}
	}
	return maxv;
}

int h[MAX];

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

	cout << getLargestRectangle( N, h ) << endl;;

	return 0;
}



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

int a[5];

int main () {

	cin>> a[0] >> a[1] >> a[2];
	int mini = 1e9;
	for (int i = 0; i < 3; i ++) {
		for (int j = 0; j < 3; j ++) {
			if (i == j) continue;
			for (int k = 0; k < 3; k ++) {
				if (i == k || j == k) continue;
				
				mini = min(mini, abs(a[i] - a[j]) + abs(a[j] - a[k]));
			}
		}
	}
	
	cout << mini;

	return 0;
}

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

using namespace std;

using ll = long long;

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

    vector<ll> s(n + 1);
    map<ll, ll> nums;

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

    for (int i = 0; i < n + 1; i++) {
        nums[s[i]]++;
    }

    ll ans = 0;
    for (auto&& x : nums) {
        ll value = x.second;
        ans += value * (value - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

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

const int N = 1e5+5;

char A[N];

int main() {
	scanf("%s", A+1);
	int n = strlen(A+1);
	long k;
	cin >> k;
	int pos = 1;
	for(int i = 1; i <= n; ++i) {
		if(A[i] != '1') {
			pos = i;
			break;
		}
	}
	if(pos > k) return !printf("1");
	printf("%c", A[pos]);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
#include <random>
#include <cassert>
#include <sstream>
using namespace std;
#define F first
#define S second
#define pb push_back
#define MP make_pair
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ln(i, n) " \n"[i == n]
typedef long long LL;
typedef long double LDB;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
//////////////////////
const long double eps = 1e-13;
const long double PI = acos(-1);
const int INF = (int)1e9;
const LL  INFF = (LL)1e15;
const int mod = 998244353;
const int MXN = (int)1e2 + 7;
char s[5][MXN];
int ck[MXN];
int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= 3; i++)
		scanf("%s", s[i] + 1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 26; j++)
			ck[j] = 0;
		int num = 0;
		for (int j = 1; j <= 3; j++) {
			if (!ck[ s[j][i] - 'a' ]++)
				num++;
		}
		if (num == 2) ans += 1;
		else if (num == 3) ans += 2;
	}
	printf("%d\n", ans);
	return 0;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#endif

#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 pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int K;
    cin >> K;

    vector<int> first_t(K, -1);
    int x = 0;
    int t = 0;
    first_t[0] = 0;
    int result;
    while (true) {
        ++t;
        x = (10 * x + 7) % K;
        if (first_t[x] == -1) {
            first_t[x] = t;
        } else {
            if (x == 0) {
                result = t;
            } else {
                result = -1;
            }
            break;
        }
    }
    cout << result << endl;

    return 0;
}


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&a!=c) cout<<"Yes"<<endl;
  else if(b==c&&b!=a) cout<<"Yes"<<endl;
  else if(c==a&&c!=b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mem(a,b) memset(a,(b),sizeof(a))
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define all(cont) cont.begin(),cont.end()
#define rall(cont) cont.rbegin(),cont.rend()
#define mp make_pair
#define pb push_back
typedef long long ll;
#define MOD 1000000007
ll gcd(ll a,ll b){if (b == 0)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p){ll res=1;x=x%p;if(x==0)return 0;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res%MOD;}  

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

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

#include <functional>
#include <climits>

//SegmentTree<int> seg(N,[](int a,int b){return min(a,b);},INT_MAX);
template< typename T>
class SegmentTree{
public:

  using F = function<T(T,T)>;

  int n;
  vector<T> tree;
  const F operation;
  const T def;

  SegmentTree(int size,F _operation,T _def):operation(_operation),def(_def){
    n=1;
    while(n<size) n*=2;
    tree.resize(2*n-1,def);
  }

  void initialize(vector<T> v){
    int vSize=v.size();
    n=1;
    while(n<vSize) n*=2;
    tree.resize(2*n-1,def);

    for(int i=0;i<vSize;i++) tree[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--) tree[i]=operation(tree[2*i+1],tree[2*i+2]);
  }

  void update(int index,T value){
    index+=n-1;

    tree[index]=value;
    while(index>0){
      index=(index-1)/2;
      tree[index]=operation(tree[2*index+1],tree[2*index+2]);
    }
  }

  T query(int a,int b,int k=0,int l=0,int r=-1){//[a,b),getMin(a,b,0,0,-1)
    if(r<0) r=n;

    if(r<=a||b<=l) return def;
    else if(a<=l&&r<=b) return tree[k];
    else{
      T lval=query(a,b,2*k+1,l,(l+r)/2);
      T rval=query(a,b,2*k+2,(l+r)/2,r);
      return operation(lval,rval);
    }
  }
};


int dp[100010];
const int INF=1e9;

int main(){
  int N,M;
  cin>>N>>M;
  string S;
  cin>>S;

  SegmentTree<int> seg(N+1,[](int a,int b){return min(a,b);},INF);
  vector<int> dp(N+1,INF);
  seg.update(N,0);
  dp[N]=0;
  for(int i=N-1;i>=0;i--){
      if(S[i]=='1') continue;
      int qry=seg.query(i,min(N+1,i+M+1));
      if(qry==INF) continue;

      seg.update(i,qry+1);
      dp[i]=qry+1;
  }

  if(dp[0]==INF) cout<<-1<<endl;
  else{
      vector<int> ans;
      int now=0;
      SegmentTree<pair<int,int>> sg(N+1,[](pair<int,int> a,pair<int,int> b){
          if(a.first<b.first) return a;
          else if(a.first>b.first) return b;
          else if(a.second<b.second) return a;
          else return b;
      },mkp(INF,INF));
      
      vector<pair<int,int>> v(N+1);
      for(int i=0;i<=N;i++) v[i]=mkp(dp[i],i);
      sg.initialize(v);

      while(now<N){
          auto q=sg.query(now+1,min(N+1,now+M+1));
          //cout<<now<<" "<<q.first<<" "<<q.second<<endl;
          ans.push_back(q.second-now);
          now=q.second;
      }
      for(auto n:ans) cout<<n<<" ";
      cout<<endl;
  }

  return 0;
}


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

#define NMAX 200100
#define INF 2000000000

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)

typedef unsigned long long ull;
typedef long long int lli;

using namespace std;

// std::ifstream cin("f.in");
// std::ofstream cout("f.out");

int numbers[NMAX];
int n;
int st[NMAX], dr[NMAX];

int cmmdc(int a, int b)
{
    int c;
    while(b)
    {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

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

    for(int i = 0; i < n; i++)
        st[i + 1] = cmmdc(st[i], numbers[i]);

    for(int i = n; i > 0; i--)
        dr[i] = cmmdc(dr[i + 1], numbers[i - 1]);

    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans = MAX(ans, cmmdc(st[i - 1], dr[i + 1]));
    
    cout << ans << '\n';
    return 0;
}   

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define forn(i,n,m) for(int (i)=(n);i<=(int)(m);(i)++)
#define pb push_back
#define mp make_pair
#define re return
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF=1e9;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef queue <int> qi;
string s,t;
int n,m;
string del;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s>>t;
	cin>>n>>m;
	cin>>del;
	if(s==del)cout<<n-1<<" "<<m;
	else cout<<n<<" "<<m-1; 
	return 0;
}

Measured memory_bytes: 256
a = input()
for i in (1, -1):
    for j in (1, -1):
        for k in (1, -1):
            if int(a[0])+i*int(a[1])+j*int(a[2])+k*int(a[3]) == 7:
                if i == 1:
                    b = '+'+str(i*int(a[1]))
                else:
                    b = str(i*int(a[1]))
                if j == 1:
                    c = '+'+str(j*int(a[2]))
                else:
                    c = str(j*int(a[2]))
                if k == 1:
                    d = '+'+str(k*int(a[3]))
                else:
                    d = str(k*int(a[3]))
                print(a[0]+b+c+d+'=7')
                exit()

Measured memory_bytes: 3064
from collections import deque

n=int(input())
a=[list(map(int,input().split())) for i in range(n)]

for i in range(n):
    for j in range(n-1):
        a[i][j]-=1
    a[i].reverse()
# print(a)
day=[0]*n
pair=[-1]*n

q=deque(range(n))

while q:
    me=q.popleft()
    if not a[me]:
        continue
    oppo=a[me].pop()
    if pair[oppo]==me:
        now=max(day[me],day[oppo])+1
        day[me]=now
        day[oppo]=now
        q.append(me)
        q.append(oppo)
    else:
        pair[me]=oppo


for i in range(n):
    if a[i]:
        print(-1)
        break
else:
    print(max(day))

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


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int n)
{
    if(n==0) return 1;
    if(n==1) return a;
    int res=modp(a,n/2);
    if(n%2==0) return (res*res);
    else return (a*res*res);
}

vi adj[1000005],ans;
vector<bool> vis(1000005,false);
map<pii,int> problem,elected;
int check=0;

bool dfs(int s)
{
    bool y=0;
    vis[s]=true;
    for(int u:adj[s])
    {
        if(!vis[u])
        {
            vis[u]=true;
            if(problem[{u,s}]||problem[{s,u}])
            {
                y=1;
                if(!dfs(u))
                {
                    ans.pb(u);
                }
            }
            else
            {
                if(dfs(u))
                {
                    y=1;
                }
            }
        }
    }
    return y;
}

void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    // int f,g,d;
    cin>>n;
    vi a(n);
    rep(i,0,n) cin>>a[i];
    vi dp(n,1000000);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    rep(i,2,n)
    {
        dp[i]=min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1];
}


signed main()
{
    //#ifndef ONLINE_JUDGE 
    //   freopen("input.txt","r",stdin);
  //     freopen("output.txt","w",stdout);
//    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 25344
import java.awt.Robot;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ======================================================================
    public void solve() {
    	int N = ns().length();
    	for (int i = 0; i < N; i++) {
			out.print('x');
		}
    	out.println("");
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a<b) System.out.println("a < b");
        if(a>b) System.out.println("a > b");
        if(a==b) System.out.println("a == b");




    }
}


Measured memory_bytes: 26248
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(i,x.size()) cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const int mod = 998244353;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

mint dp[3005][3005];

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = a; i <= c; i++) {
        for (int j = b; j <= d; j++) {
            if (i == a && j == b) continue;
            dp[i][j] = dp[i-1][j]*j+dp[i][j-1]*i;
            if (i != a && j != b) dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1);
        }
    }
    cout << dp[c][d] << endl;
}

Measured memory_bytes: 74192
#include<bits/stdc++.h>
using namespace std;
int used[10];
int d[10];
int G[10][10];
int n,ans;

int ch(){
  for(int i=1;i<n;i++){
    if(G[d[i-1]][d[i]])continue;
    return 0;
  }
  return 1;
}

void rec(int x){
  if(x==n){
    if(ch())ans++;
    return;
  }
  for(int i=1;i<n;i++){
    if(used[i])continue;
    used[i]=1;
    d[x]=i;
    rec(x+1);
    used[i]=0;
  }
}

int main(){
  int m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a][b]=G[b][a]=1;
  }
  used[0]=1;
  rec(1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int n = fs.nextInt();
		
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		
		for(int i = 0; i < n; i++) {
			String s = fs.next();
			if(s.equals("AC")) {
				ac++;
			}else if(s.equals("WA")) {
				wa++;
			}else if(s.equals("TLE")) {
				tle++;
			}else if(s.equals("RE")) {
				re++;
			}
		}
		
		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 48120
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int[] line = ReadIntArray();
    int A = line[0], B = line[1], K = line[2];
    for (int i = Math.Min(A, B), j = 1; i > 0; i--) {
      if (A % i == 0 && B % i == 0) {
        if (j == K) {
          Console.WriteLine(i);
          return;
        } else {
          j++;
        }
      }
    }
  }

  private static string ReadStr() { return Console.ReadLine(); }
  private static int ReadInt() { return int.Parse(Console.ReadLine()); }
  private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  private static long ReadLong() { return long.Parse(Console.ReadLine()); }
  private static char ReadChar() { return Console.ReadLine()[0]; }
  private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  private static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


Measured memory_bytes: 13396
import sys
input=sys.stdin.readline
import fractions

def main():
    _,K = map(int, input().split())
    A = list(map(int, input().split()))
    a = A[0]
    for x in A:
        a = fractions.gcd(a,x)
    if max(A) >= K and K%a == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == '__main__':
    main()


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

int func(int x) {
    if(x % 100 != 0)
        return 0;

    return func(x / 100) + 1;
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    string s;
    unsigned long k;
    cin >> s >> k;
    int onecnt = 0;
    rep(i, s.size()) {
        if(s[i] == '1') {
            onecnt++;
        } else {
            break;
        }
    }
    if(onecnt<k){
        cout <<s[onecnt]<<endl;
    }else{
        cout << 1 <<endl;
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
int n,a[200005],tmp=0,tmp2=0;
ll k;
ll Check(ll x) {
	ll ret=0;
	if(x>=0) {
		ret=1ll*tmp2*(2*n-tmp2-1)/2+1ll*tmp*(n-tmp-tmp2);
		for(int i=tmp+tmp2+1,j=n; i<=n; i++) {
			while(j>tmp+tmp2&&1ll*a[i]*a[j]>x)j--;
		//	cout<<i<<' '<<j<<endl;
			if(j<=i)break;
			ret+=j-i;
		}
		for(int i=tmp,j=1; i>0; i--) {
			while(j<=tmp&&1ll*a[i]*a[j]>x)j++;
		//	cout<<i<<' '<<j<<endl;
			if(j>=i)break;
			ret+=i-j;
		}
		return ret;
	}
	else {
		for(int i=1,j=tmp+tmp2+1;i<=tmp;i++){
			while(j<=n&&1ll*a[i]*a[j]>x)j++;
			ret+=n-j+1;
		}
	}
	return ret;
}
int main() {
	scanf("%d%lld",&n,&k);
	for(int i=1; i<=n; i++)scanf("%d",&a[i]),tmp+=(a[i]<0),tmp2+=(a[i]==0);
//	cout<<tmp<<' '<<tmp2<<endl;
//	Check(1000000000000000000ll);
//	return 0;
	sort(a+1,a+n+1);
	ll l=-1000000000000000000ll,r=1000000000000000000ll,ans=0;
	while(l<=r) {
		ll mid=(l+r)/2;
		//cout<<mid<<' '<<Check(mid)<<endl;
		if(Check(mid)>=k)ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define s second
#define mk make_pair
#define f first
using namespace std;
int main(){
  int n,m,w;
  while(cin>>n>>m,n){
    int pp=0;string q;
    vector<pair<pair<int,string>,int> >p;
    for(int i=0;i<n;i++){
      cin>>q>>w;
      p.push_back(mk(mk(w,q),i+1));
    }
    //p.erase(p.begin());
    for(int i=0;i<10000000;i++){//if(i==4){cout<<p.size();break;}
      for(int j=0;j<p.size();j++){
     	 if(p[j].f.s=="R")p[j].f.f+=1;
       else p[j].f.f-=1;
    	}
      sort(p.begin(),p.end());
      int e=1;
      for(int j=0;j<p.size();j++)
        if(p[j].f.f<=0||p[j].f.f>=m){//cout<<p.size();
          if(e)pp=p[j].s,e=0;//cout<<pp<<endl;
          p.erase(p.begin()+j);j--;
        }
      if(p.size())for(int j=0;j<p.size()-1;j++)
        if(p[j].f.f==p[j+1].f.f){
	        if(p[j].f.s=="R")p[j].f.s="L";
	        else p[j].f.s="R";
	        if(p[j+1].f.s=="R")p[j+1].f.s="L";
	        else p[j+1].f.s="R";
	      }
      if(p.size()<=0){
	      cout<<i+1<<' '<<pp<<endl;
	      break;
      }
    }
  }
}

Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

}


Measured memory_bytes: 21332
# n = int(input())
# lists = []
# for i in range(n):
#     lists.append(list(map(int,input().split())))
# print(lists)
# lists.sort()
# print(lists)
n = int(input())
lists = list(map(int,input().split()))
lists.sort()
plus = []
minus = []
total = 0
for a in lists:
    if a < 0:
        minus.append(a)
    else:
        plus.append(a)
mini = min(len(minus), len(plus))
flag = (mini == len(plus))              #プラスのほうが少ないとき
eq_flag = (len(plus) == len(minus))     #プラスの数とマイナスの数が同じだったとき
zero_flag = (mini == 0)                 #符号が偏ってたとき
minus.reverse()


sum_list = 0

total = 0
if len(minus) == 0:
    print(sum(plus)-plus[0]*2)
    total = plus[0]
    for i in range(1,len(plus)-1):
        print(total, plus[i])
        total = total - plus[i]
    print(plus[-1], total)
elif len(plus) == 0:
    print(abs(sum(minus))-abs(minus[0]*2))
    total = minus[0]
    for i in range(1,len(minus)-1):
        print(total, minus[i])
        total = total - minus[i]
    print(total, minus[-1])
else:
    print(abs(sum(plus))+abs(sum(minus)))
    total = minus[-1]
    for i in range(len(plus)-1):
        print(total, plus[i])
        total = total - plus[i]
    print(plus[-1], total)
    total = plus[-1] - total
    for i in range(len(minus)-1):
        print(total, minus[i])
        total = total - minus[i]






Measured memory_bytes: 14004
#include <stdio.h>
int main(){
  int n, tmp=0, cnt[10050+1]={0};
  scanf("%d", &n);
  for(int x=1; x<105; x++){
    for(int y=1; y<105; y++){
      for(int z=1; z<105; z++){
        tmp = x*x + y*y + z*z + x*y + y*z + z*x;
        if( tmp < 10050 ){ cnt[tmp]++; }
      }
    }
  }
  for(int i=1; i<=n; i++){ printf("%d\n",cnt[i]); }
  return 0;
}

Measured memory_bytes: 1716
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n), q(n),r(n),s(n);
	rep(i, n)cin >> p[i];
	rep(i, n)cin >> q[i];
	r = p;
	sort(r.begin(), r.end());
	s = r;
	int a = 0;
	int b = 0;
	while (p != r) {
		next_permutation(r.begin(), r.end());
		a++;
	}
	while (q != s) {
		next_permutation(s.begin(), s.end());
		b++;
	}
	cout << abs(b - a);
}

Measured memory_bytes: 256
def tax(p,x):
    return p*(100+x)//100
def solve(X, Y, S):
    max_value=0 #max_valueをdef solveの前に入れるミスをしていて全く進みませんでした。関数の定義の理解が進みました。
    for a in range(1,S):
        for b in range(1,S):
            sum_value=tax(a,X)+tax(b,X)
            if sum_value==S:
                c=tax(a,Y)+tax(b,Y)
                if c>max_value:#最初は>=にしてたのですが、> にすることで高速化を図れました
                    max_value=c
                if sum_value>S: #bが増加すれば必ずSが増加することを使っていて、なるほどと思いました。
                    break
    return max_value

while True:
    X,Y,Z=map(int, input().split())
    if X==0:
        break
    print(solve(X,Y,Z))
#runtime errorになりましたが、ジャッジングデータと結果が一致しました。制限時間内に解く方法がわかりませんでした。
#右・中央の座席


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

using namespace std;

int main(){
	int N;
    cin>>N;
	vector<int>s(N);
	int ans=0;
	for(int i=0;i<N;++i){
		cin>>s[i];
		ans+=s[i];
	}
	sort(s.begin(),s.end());
	if(ans%10){
		cout<<ans<<endl;
		return 0;
	}
	for(auto x:s){
		if(x%10){
			ans-=x;
			break;
		}
	}
	if(!(ans%10)){
		ans=0;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
vector<vector<int>> graph;
void bfs(vector<int>& from, vector<bool>& searched){
    queue<pair<int, int>> q;
    q.emplace(0, -1);
    while(!q.empty()){
        auto p = q.front();
        q.pop();
        if(searched[p.first]) continue;
        from[p.first] = p.second;
        searched[p.first] = true;
        for(auto to : graph[p.first]){
            if(!searched[to])q.emplace(to, p.first);
        }
    }
}
int main(){
    int n, m;
    cin >> n >> m;
    graph.resize(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        graph[a - 1].push_back(b - 1);
        graph[b - 1].push_back(a - 1);
    }
    vector<int> from(n);
    vector<bool> searched(n);
    bfs(from, searched);
    cout << "Yes" << "\n";
    for(int i = 1; i < n; i++){
        cout << from[i] + 1 << "\n";
    }
}


Measured memory_bytes: 10748
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string circle,str;
    getline(cin,circle);
    getline(cin,str);
    int circle_pointer=0;
    int str_pointer=0;
    bool tmp= true;
    int number=0;
    for(int i=0;i<circle.length();i++)
    {
        if(circle[i]==str[0]){
            circle_pointer=i;
            str_pointer=0;
            tmp=true;
            while (tmp&&str_pointer<str.length()) {
                str_pointer++;
                if (circle_pointer <circle.length()-1)
                    circle_pointer++;
                else  if (circle_pointer==circle.length()-1)
                    circle_pointer = 0;
                tmp=(str[str_pointer]==circle[circle_pointer]);
            }
        }
        if(str_pointer==str.length()) number++;

    }

    if(number) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3208
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, x = map(int, input().split())
ca = [0] * n
ca_sum = [0] * (m+1)
for i in range(n):
    ca[i] = list(map(int, input().split()))
    for j in range(m+1):
        ca_sum[j] += ca[i][j]

ans = 10 ** 10
for i in range(2 ** n):
    tmp = 0
    tmp_ca_sum = ca_sum.copy()
    for j, v in enumerate(format(i, r'0{}b'.format(n))):
        if v == '0':
            continue
        for k in range(m+1):
            tmp_ca_sum[k] -= ca[j][k]
    flag = True
    for v2 in tmp_ca_sum[1:]:
        if v2 < x:
            flag = False
            break
    if flag:
        ans = min(ans, tmp_ca_sum[0])

if ans == 10 ** 10:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 68700
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}

int main(){
    int m,d,ans=0;

    cin >> m >>d;

    for(int i = 1;i<=m;i++){
        for(int j = 1; j<= d;j++){
            if(j < 10){
                continue;
            }else{
                int a,b;
                a = j/10;
                b = j%10;

                if((a >=2)&&(b >= 2)&&(a*b == i)) ans++;
            }
        }
    }
    
    cout << ans <<endl;
}






Measured memory_bytes: 256
N = int(input())
W_list = [int(x) for x in input().split()]
s = 0
sums = []
for w in W_list:
    s += w
    sums.append(s)
total = sums[-1]
delta = [abs(sums[i]-(total-sums[i])) for i, s in enumerate(sums[1:])]
print(min(delta))


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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << (a == b && b == c ? "Yes" : "No");
}

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

int main(){
	int k,n;
		cin >> k >> n;
	vector<int> a(n);
	int max_distance=0;
	int distance;

	for(int i=0;i<n;i++){
			cin >> a[i];
	}
	for(int i=0;i<n;i++){
		if( i< n-1 ){
			if((a[i+1]-a[i]) > max_distance )	max_distance = a[i+1]-a[i];
		}
		if( i== n-1 ){
			if((k-a[n-1]+a[0]) > max_distance )	max_distance=k-a[n-1]+a[0];
		}
	}
	distance = k - max_distance;
	cout << distance << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    double T, X;
    cin >> T >> X;
    std::cout << std::fixed << std::setprecision(10);
    cout << T / X << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
//using namespace std;
int main() {
	 int t,t1=0,x,y,x1=0,y1=0;
	 int n,i,flag=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++) {
		scanf("%d %d %d",&t,&x,&y);//printf("%d %d %d\n",t,x,y);
		if(t>=(t1+abs(x-x1)+abs(y-y1))&&((t-t1-abs(x-x1)-abs(y-y1))%2==0)) {
			x1=x; y1=y;	t1=t;
		}
		else {
			flag=0;	
		}
	}
	if(flag==1) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String[] s = new String[N];
    int[] t = new int[N];
    for (int i = 0; i < N; i++) {
      s[i] = sc.next();
      t[i] = sc.nextInt();
    }
    String X = sc.next();
    sc.close();

    boolean sleep = false;
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (sleep) ans += t[i];
      if (X.equals(s[i])) sleep = true;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
#include <stdio.h>
#define isNum(a) (a<='9'&&a>='0')
#define N_MAX 10000 // 適当

char ch;
int c[N_MAX], f[N_MAX];

int parseInt()
{
     int res = ch-'0';
     while(ch=getchar(), isNum(ch)) res = res*10 + ch-'0';
     return res;
}

int main(void){
     int n;

     for(n=0; n<N_MAX; n++) c[n]=f[n]=0;

     while(ch=getchar(), isNum(ch)){
	  n = parseInt();
	  c[n]++, f[n]=-1;

	  while(ch!='\n') ch=getchar();
     }

     while(ch=getchar(), isNum(ch)){
	  n = parseInt();
	  c[n]++, f[n]=f[n]?1:0;

	  while(ch!='\n') ch=getchar();
     }

     for(n=0; n<N_MAX; n++)
	  if(f[n]==1)
	       printf("%d %d\n",n,c[n]);

     return 0;
}

Measured memory_bytes: 0
// algo.cpp: 定义应用程序的入口点。
//
#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;
struct UnionFind {
    vector<int> par, sz;
    int n_tree;

    explicit UnionFind(int n) : par(n), sz(n, 1), n_tree(n) { //0-indexed
        iota(par.begin(), par.end(), 0);
    }

    int n_cluster() const {
        return n_tree;
    }

    int size(int x) {
        return sz[root(x)];
    }

    int root(int x) {
        return x == par[x] ? x : par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx != ry) {
            par[rx] = ry;
            --n_tree;
            sz[ry] += sz[rx];
            return true;
        }
        return false;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool is_root(int x) const {
        return par[x] == x;
    }
};
int gcd(int x, int y) {
    return y == 0 ? x : gcd(y, x % y);
}
int main() {
#ifdef LOCAL
    // 如何使用相对路径？
    ifstream in("in.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //aoki一直向下走
    //相遇点不可能是叶子。
    int n, u, v;
    cin >> n >> u >> v;
    --u, --v;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<int> depth(n);
    vector<int> max_leaf_depth(n);
    function<bool(int,int)> dfs = [&](int x, int fa) {
        bool flag = x == u;
        for (int y : g[x]) {
            if (y != fa) {
                depth[y] = depth[x] + 1;
                max_leaf_depth[y] = depth[y];
                flag |= dfs(y, x);
                max_leaf_depth[x] = max(max_leaf_depth[x], max_leaf_depth[y]);
            }
        }
        if (flag && depth[x] == depth[u] - (depth[u] - 1) / 2) {
            cout << max_leaf_depth[x] - 1 << endl;
            exit(0);
        }
        return flag;
    };
    dfs(v, v);
#if defined LOCAL
    cout << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 15488
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


inline void print(){
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest){
    cout << first << ' ';
    print(rest...);
}


struct UnionFind {
    vector<int> par;    // 親ノード
    vector<int> rank;   // ランク
    vector<int> siz;

    UnionFind (int n = 1 ) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); siz.resize(n);
        for (int i = 0; i < n; i++) par[i] = i, rank[i] = 0, siz[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
        }
        else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};


void solve() {
    int N, M, K; cin >> N >> M >> K;

    UnionFind uf(N);

    vector<vector<int>> fri(N);
    vector<vector<int>> block(N);

    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--; b--;
        uf.unite(a, b);
        fri[a].push_back(b); fri[b].push_back(a);
    }

    for (int i = 0; i < K; i++) {
        int c, d; cin >> c >> d; c--; d--;
        block[c].push_back(d); block[d].push_back(c);
    }

    for (int i = 0; i < N; i++) {
        int minus = 1;

        for (int j = 0; j < fri[i].size(); j++) {
            if (uf.same(i, fri[i][j])) minus++;
        }
        for (int j = 0; j < block[i].size(); j++) {
            if (uf.same(i, block[i][j])) minus++;
        }

        cout << uf.size(i) - minus << endl;
    }
}


int main() {
    solve();
    return 0;
}

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

int main() {
    cin.sync_with_stdio(false);
    cin.tie();

    vector<int> prev(3, 0);
    vector<int> cur(3);

    int N;
    cin >> N;
    cin >> cur[0] >> cur[1] >> cur[2];
    for (int i = 1; i < N; ++i) {
        std::swap(prev, cur);
        for (int i = 0; i < 3; ++i) {
            cin >> cur[i];
            cur[i] += max(prev[(i + 1) % 3], prev[(i + 2) % 3]);
        }
    }
    int ans = max(max(cur[0], cur[1]), cur[2]);
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

void ok(){
  cout << "Yes" << endl;
  exit(0);
}

void ng(){
  cout <<  "No" << endl;
  exit(0);
}
bool used[108000];
vector<int> edge[108000];
vector<int> just4;
int cnt[108000];
int over4, a, b, n, m;
void dfs(int x){
  used[x] = true;
  for(int to: edge[x]){
    if(used[to])continue;
    dfs(to);
  }
}

int main(){
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    cin >> a >> b;a--,b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
    cnt[a]++;
    cnt[b]++;
  }
  for(int i = 0;i < n;i++){
    if(cnt[i] % 2 == 1)ng();
    if(cnt[i] > 4)over4++;
    if(cnt[i] == 4)just4.push_back(i);
  }
  if(over4)ok();
  if(just4.size() < 2)ng();
  if(just4.size() > 2)ok();

  used[just4[0]] = true;
  int component = 0;
  for(int i = 0;i < n;i++){
    if(used[i])continue;
    component++;
    dfs(i);
  }
  if(component == 1)ng();
  else ok();
  return 0;
}

Measured memory_bytes: 7680
S = input()

res = [[S[0]]]

for c in S[1:]:
    buf = []
    for dp in res[-1]:
        buf.append(dp+c)
        buf.append(dp+'+'+c)
    res.append(buf)
sum_num = 0

for string in res[-1]:
    sum_num += sum(map(int, string.split('+')))
print(sum_num)

Measured memory_bytes: 65604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  ll X;
  cin >> X;
  ll ans = 0;
  ans += X / 500 * 1000;
  X %= 500;
  ans += X / 5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256