akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=2e6,mod=1e9+7;
int x[7],y[7];
int fac[maxn+5],ifac[maxn+5];
int ans;
int C(int n,int m){return 1ll*fac[n+m]*ifac[n]%mod*ifac[m]%mod;}
int calc(int x1,int y1,int x2,int y2){
	return
		1ll*
		(C(x1-x[1]+1,y1-y[1]+1)-C(x1-x[2],y1-y[1]+1)-C(x1-x[1]+1,y1-y[2])+C(x1-x[2],y1-y[2]))*
		(C(x[6]-x2+1,y[6]-y2+1)-C(x[5]-x2,y[6]-y2+1)-C(x[6]-x2+1,y[5]-y2)+C(x[5]-x2,y[5]-y2))%mod;
}
int main(){
	rep(i,1,6)read(x[i]);
	rep(i,1,6)read(y[i]);
	fac[0]=1;rep(i,1,maxn)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[maxn]=power(fac[maxn],mod-2,mod);per(i,maxn-1,0)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	rep(i,x[3],x[4])ans=(ans+1ll*calc(i,y[4],i,y[4]+1)*(i+y[4]+1)-1ll*calc(i,y[3]-1,i,y[3])*(i+y[3]))%mod;
	rep(i,y[3],y[4])ans=(ans+1ll*calc(x[4],i,x[4]+1,i)*(i+x[4]+1)-1ll*calc(x[3]-1,i,x[3],i)*(i+x[3]))%mod;
	cout<<(ans+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 10000
using namespace std;
int ans,cou;
int n;
char s[10],g[10];
struct t {
  int h;
  int m;
  int s;
};
t start[MAX],goal[MAX];
int main() {
  while(true){
    cin >> n;
    if(n==0) return 0;
    ans = 0;
    cou = 0;
    rep(i,n){
      cin >> s >> g;
      start[i] = t();
      goal[i] = t();
      start[i].h = (int)(s[0]-'0')*10+(int)(s[1]-'0');
      start[i].m = (int)(s[3]-'0')*10+(int)(s[4]-'0');
      start[i].s = (int)(s[6]-'0')*10+(int)(s[7]-'0');
      goal[i].h = (int)(g[0]-'0')*10+(int)(g[1]-'0');
      goal[i].m = (int)(g[3]-'0')*10+(int)(g[4]-'0');
      goal[i].s = (int)(g[6]-'0')*10+(int)(g[7]-'0');
    }
    rep(i,24) rep(j,60) rep(k,60){
      rep(l,n){
        if(goal[l].h==i&&goal[l].m==j&&goal[l].s==k) cou--;
        if(start[l].h==i&&start[l].m==j&&start[l].s==k) cou++;
      }
      if(cou>ans) ans = cou;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1392
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int a[300000];

int main()
{
	int N, index;
	ll ans = 0;

	cin >> N;
	rep(i, N * 3) cin >> a[i];

	sort(a, a + N * 3);
	index = N * 3 - 2;

	rep(i, N) {
		ans += a[index];
		index -= 2;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
using ll = long long;

int main()
{
  int n, k;
  cin >> n >> k;
  int d[k], a[n];

  for(int i = 0; i < n; ++i)a[i]=0;
  for(int i = 0; i < k; ++i)d[i]=0;

  for(int i = 0; i < k; ++i){
    cin >> d[i];
    for( int j = 0; j < d[i]; ++j){
      int s;
      cin >> s;
      a[s-1] += 1;
    }
  }

  int ret = 0;
  for(int x = 0; x < n; ++x){
    if(a[x] == 0){
      ret += 1;
    }
  }

  cout << ret << endl;

  return 0;
}

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

int main()
{
    int n;
    cin>>n;
    vector<int>g[n+2];
    vector<pair<int,int>>vp;
    for(int i=1;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        vp.emplace_back(a,b);
    }

    int k=0;
    map<pair<int,int>,int>I;
    vector<int>used(n+2,0);
    vector<int>cs(n+2,0);

    queue<int>q;
    q.emplace(1);
    used[1]=1;
    int sizen=0;

    while(!q.empty())
    {
        int v=q.front();
        q.pop();
        int k= g[v].size();
        sizen= max(sizen,k);
        int cur=1;
        for(auto u:g[v])
        {
            if(used[u]==1)continue;
            if(cur==cs[v])cur++;
            cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
            used[u]=1;
            q.emplace(u);
        }

    }

    cout<<sizen<<endl;
    for(auto v:vp)
        cout<<I[v]<<endl;


    return 0;
}


Measured memory_bytes: 20084
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

void solve(const int x, const int y, const int k, vector<pair<int, int>> &result)
{
    if (x + y == k)
    {
        result.push_back(make_pair(x, y));
        return;
    }
    if (x + y > k || (x + y) % 2 == 0)
    {
        int f = (x + y + k - 1) % k + 1;
        int rCand = k - f;
        int r = rCand % 2 != 0 || x + y < k ? rCand + k : rCand;

        int cx = 0, cy = 0;
        while (cx != x || cy != y)
        {
            if (cx == 0)
            {
                int c = min(r / 2 + cy, k);
                cy -= c;
                cx += k - c;
            }
            else if (cy == -r / 2)
            {
                int c = min(x - cx, k);
                cx += c;
                cy += k - c;
            }
            else
            {
                cy += k;
            }

            result.push_back(make_pair(cx, cy));
        }
    }
    else
    {
        result.push_back(make_pair(x, -(k - x)));
        result.push_back(make_pair(x + (x - y + k) / 2, (y + k - x) / 2 - (k - x)));
        result.push_back(make_pair(x, y));
    }
}

int main()
{
    int k;
    int x, y;

    cin >> k;
    cin >> x >> y;

    if (k % 2 == 0 && (x + y + 200'000) % 2 == 1)
    {
        cout << -1 << endl;
        return 0;
    }

    bool xFlip = false;
    bool yFlip = false;
    bool xySwap = false;
    if (x < 0)
    {
        x *= -1;
        xFlip = true;
    }
    if (y < 0)
    {
        y *= -1;
        yFlip = true;
    }
    if (x < y)
    {
        swap(x, y);
        xySwap = true;
    }

    vector<pair<int, int>> result;
    solve(x, y, k, result);

    cout << result.size() << endl;
    for (int i = 0; i < result.size(); i++)
    {
        auto &pos = result[i];
        int cx = pos.first;
        int cy = pos.second;
        if (xySwap)
        {
            swap(cx, cy);
        }
        cx *= xFlip ? -1 : 1;
        cy *= yFlip ? -1 : 1;
        cout << cx << " " << cy << endl;
    }

    return 0;
}

Measured memory_bytes: 3952
<?php
  $input=explode(' ',trim(fgets(STDIN)));
  $a=intval($input[0]);
  $b=intval($input[1]);   //A,B,Cそれぞれを$a,$b,$cに格納

          if((-100 <= $a)&&(100 >= $a)&&($b <= 100)&&($b >= -100)){
            $p = $a + $b;     //$sはAとBの和
            $q = $a - $b;     //$sはAとBの差
            $r = $a * $b;     //$sはAとBの積
            if(($p >= $q)&&($p >= $r)){
              echo $p;
            }else if(($q >= $r)&&($q >= $p)){
              echo $q;
            }else  if(($r >= $q)&&($r >= $p)){
              echo $r;
            }
          }
?>


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,t;
ll a[3010],b[3010];
ll dp1[3010][3010];
ll dp2[3010][3010];
int main(){
	cin>>n>>t;
	FOR(i,1,n+1)cin>>a[i]>>b[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<t;j++){
			dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
			if(j>=a[i+1]){
				dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j-a[i+1]]+b[i+1]);
			}
		}
	}
	for(int i=n+1;i>1;i--){
		for(int j=0;j<t;j++){
			dp2[i-1][j]=max(dp2[i-1][j],dp2[i][j]);
			if(j>=a[i-1]){
				dp2[i-1][j]=max(dp2[i][j],dp2[i][j-a[i-1]]+b[i-1]);
			}
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<t;j++){
			ans=max(ans,dp1[i-1][j]+dp2[i+1][t-j-1]+b[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(){
        int a, b;
        string s;
        cin>>a>>b>>s;
        bool res=true;
        for(int i=0;i<(int)s.length();i++){
                //cout<<"s["<<i<<"]=="<<s[i]<<endl;
                if((i!=a&&(s[i]>'9'||s[i]<'0'))||(i==a&&s[i]!='-')){
                        res=false;
                        break;
                }
        }
        if(res&&(int)s.length()==a+b+1){
                cout<<"Yes"<<endl;
        }
        else{
                cout<<"No"<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <numeric>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/*
.-.. . -. -.- .- / .. ... / .-.. --- ...- . -.-.--
 */
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    ll n;
    cin >> n;
    
    vi ans(n + 1);

    for(ll x = 1; x <= 100; x++){
        for(ll y = 1; y <= 100; y++){
            for(ll z = 1; z <= 100; z++){
                ll val = x * x + y * y + z * z + x * y + y * z + z * x;
                if(val <= n)
                    ans[val]++;
            }
        }
    }

    for(ll i = 1; i <= n; i++)
        cout << ans[i] << endl;

    return 0;
}


signed main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}

/*******************************************************************************/
// Remeber - In a custom comparator cmp(a, b) a==b must always return to false.



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

using namespace std;

int a[100000];

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    cout<<a[n]-a[1];
    return 0;
}

Measured memory_bytes: 256
import sys

N,X=map(int,input().split())
x=list(map(int,input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

if N==1:
    print(abs(X-x[0]))
    sys.exit()



x.append(X)
x.sort()

ANS=gcd(x[1]-x[0],x[2]-x[1])

for i in range(N):
    ANS=gcd(ANS,x[i+1]-x[i])

print(ANS)


Measured memory_bytes: 14252
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int K = sc.nextInt();
		int ANS = 0;
		int K2 = K / 2;
		if (K % 2 == 0){
			ANS = K2 * K2;
		}else{
			K2 = K2 + 1;
			ANS = K2 * K2;
			ANS = ANS - K2;
		}
		System.out.println(ANS);
		
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <math.h>
using namespace std;



int main(){
  int N,D;

  cin >> N>>D;

  vector<vector<double>> z(N,vector<double>(D));

  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> z.at(i).at(j);
    }
  }

  vector<vector<double>> dis2(N,vector<double>(N));
  vector<vector<double>> dis(N,vector<double>(N));

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<D;k++){
         dis2.at(i).at(j)+=(z.at(i).at(k)-z.at(j).at(k))*(z.at(i).at(k)-z.at(j).at(k));
      }
      dis.at(i).at(j)=sqrt(dis2.at(i).at(j));
    }
  }

  int count=0;

 for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
  if(dis.at(i).at(j)==floor(dis.at(i).at(j))){
    count++;
  }
    }
 }

 cout << (count-N)/2 << endl; 


 






  }










Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;
int n,m;
char mp[105][105];
int dp[105][105];
int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            cin>>mp[i][j];
    }
    memset(dp,inf,sizeof(dp));
    dp[1][1]=0;
    if(mp[1][1]=='#')
    {
        dp[1][1]=1;
    }
    for(int i=0;i<n;i++) mp[0][i]='.';
    for(int i=0;i<m;i++) mp[i][0]='.';
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(i==1&&j==1) continue;

            //
            if(mp[i][j]=='#')
            {
                if(mp[i-1][j]=='.') dp[i][j]=min(dp[i-1][j]+1,dp[i][j]);
                else dp[i][j]=dp[i][j]=min(dp[i-1][j],dp[i][j]);
                if(mp[i][j-1]=='.') dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
                else dp[i][j]=min(dp[i][j-1],dp[i][j]);
            }
            else
                dp[i][j]=min(dp[i-1][j],dp[i][j-1]);

        }
    }
    cout<<dp[n][m]<<endl;
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=m;j++)
//            cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }

}




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

using namespace std;

//#define FILE_IO

typedef pair <int, int> pii;

int N, M;
vector <pii> itv[100005];
int sum[100005];

int aib[100005];
void U(int pos, int val)
{
    for(; pos <= M; pos += (pos & (-pos)))
        aib[pos] += val;
}
int Q(int pos)
{
    int ans = 0;
    for(; pos > 0; pos -= (pos & (-pos)))
        ans += aib[pos];
    return ans;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &M);
    for(int i = 1; i <= N; i++)
    {
        int lft, rgt;
        scanf("%d%d", &lft, &rgt);
        itv[rgt - lft + 1].push_back({lft, rgt});
        sum[rgt - lft + 1] ++;
    }

    for(int i = M; i >= 1; i--)
        sum[i] += sum[i + 1];

    for(int i = 1; i <= M; i++)
    {
        int ans = sum[i];
        for(int j = i; j <= M; j += i)
            ans += Q(j);
        printf("%d\n", ans);

        for(auto upd: itv[i])
            U(upd.first, 1), U(upd.second + 1, -1);
    }

    return 0;
}


Measured memory_bytes: 8320
str = gets.split
N,K = str[0].to_i, str[1].to_i
mod = 1000000007

a = Array.new(0)
b = Array.new(0)
size = 0

i = 1
while i <= N/i
    a.push(i)
    b.push(N/i)
    i += 1
end
i = 0
size = a.size
if a[a.size-1] == b[b.size-1]
    i += 1
end
while i < size
    a.push(b[size-1-i])
    b.push(a[size-1-i])
    i += 1
end

c = Array.new(a.size,1)
for x in 1...c.size do
    c[x] = a[x] - a[x-1]
end

d = Array.new(K){Array.new(a.size)}
for x in 0...a.size do
    d[0][x] = a[x]
end
for x in 1...K do
    d[x][0] = d[x-1][a.size-1]
    for y in 1...a.size do
        d[x][y] = (d[x][y-1] + d[x-1][a.size-1-y] * c[y]) % mod
    end
end

puts d[K-1][a.size-1]

Measured memory_bytes: 53044
#include <iostream>
#include <string>
#include <vector>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int a[101][101];
	int dx[4] = {0,1,0,-1};
	int dy[4] = {-1,0,1,0};
	
	bool first = true;

	rep(i,n)
	{
		int r;
		cin >> r;
		int r2 = r;

		memset(a,0,sizeof(a));

		if(r == 1)
		{
			if(first) first = false;
			else cout << endl;
			cout << "#" << endl;
		}
		else if(r == 2)
		{
			if(first) first = false;
			else cout << endl;
			cout << "##" << endl << "# " << endl;
		}
		else
		{
			int y = r-1;
			int x = 0;
			a[y][x] = 1;

			int dir = 0;

			rep(j,r-1)
			{
				y += dy[dir%4];
				x += dx[dir%4];
				a[y][x] = 1;
			}

			dir++;
			r--;
			
			if(r%2 == 1)
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					if(r == 1) break;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;
					r -= 2;
				}
			}
			else
			{
				while(true)
				{
					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}
					dir++;

					rep(j,r)
					{
						y += dy[dir%4];
						x += dx[dir%4];
						a[y][x] = 1;
					}

					if(r == 2 ) break;

					dir++;
					r -= 2;
				}
			}
			
			if(first) first = false;
			else cout << endl;

			rep(j,r2)
			{
				rep(k,r2)
				{
					if(a[j][k] == 1) cout << "#";
					else cout << " ";
				}
				cout << endl;
			}
		}	
	}
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,s=0,i;
    cin>>m>>n;
    while(n--)
    {
        cin>>i;
        s+=i;
    }
    if(s<=m)
        cout<<m-s;
    else
        cout<<-1;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = 1000001;
const double PI = acos(-1);

ll fexp(ll base, ll p){
    ll ans = 1;
    while (p){
        if (p&1){
            ans = (ans*base)%mod;
        }
        p = p >> 1;
        base = (base*base)%mod;
    }
    return ans;
}

int main (){
    ios_base::sync_with_stdio(false);
    ll n, h, ans = oo;

    cin >> h >> n;
    vector<ll> dp(100100, oo);
    dp[0] = 0;

    for (int i=0; i<n; i++){
        ll a, b;
        cin >> a >> b;
        for (int j=a; j<20200; j++){
            dp[j] = min(dp[j], dp[j-a] + b);
        }
    }

    for (int i=h; i<20200; i++){
        ans = min(ans, dp[i]);
    }

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

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

int main() {
  int n, k;
  cin>>n>>k;
  long long ans = 0;
  long long acc[n+2];
  long long MOD = 1e9 + 7;
  acc[0] = 0;
  acc[1] = 0;
  for (int i=1; i<=n; i++) {
    acc[i+1] = acc[i] + i;
  }
  for (int i=k; i<=n+1; i++) {
    ans += acc[n+1] - acc[n+1-i] - acc[i] + 1;
    if (ans < 0) {
      ans += MOD;
    }
    ans %= MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5140
if __FILE__==$0
	
	rl_i=lambda{|str,dl|str.strip.split(dl).map(&:to_i)}
	
	r_i=lambda{|str|str.strip.to_i}
	
	dl=" "
	#空港に到着バスに搭乗
	n,c,k=rl_i[gets,dl] #num,ac,ti
	t=Array.new(n){0}
	n.times do |x|
		t[x]=r_i[gets]
	end
	#p [c,k]
	t.sort!
	bn=1
	bc=c-1
	bk=k
	br=t.shift
	#p [br,br,bn,bc,bk]
	t.each do |x|
		bc-=1
		bk-=x-br
		br=x
		if bc<0 || bk<0
			bn+=1
			bc=c-1
			bk=k
		end
		#p [x,br,bn,bc,bk]
	end
	#p [t[-1],br,bn,bc,bk]
	p bn
end

Measured memory_bytes: 3836
use std::cmp::min;
use std::io::stdin;
use std::io::Error;
use std::io::Read;

#[derive(Debug)]
struct Input {
    n: u32,
    k: u32,
    s: Vec<ContinuousCharacters>,
}

#[derive(Debug)]
struct ContinuousCharacters {
    c: char,
    n: u32,
}

fn handle_input(input_str: String) -> Result<Input, Error> {
    let mut iter = input_str.split_whitespace();
    let n: u32 = iter.next().unwrap().parse().unwrap();
    let k: u32 = iter.next().unwrap().parse().unwrap();
    let s = iter.next().unwrap();
    let mut vec = Vec::new();
    vec.push(ContinuousCharacters { c: ' ', n: 0 });
    for c in s.chars() {
        if let Some(tail) = vec.last_mut() {
            if tail.c == c {
                tail.n += 1;
                continue;
            }
        }
        vec.push(ContinuousCharacters { c: c, n: 1 });
    }
    Ok(Input { n: n, k: k, s: vec })
}

fn handle_output(input: Input) -> Result<String, Error> {
    let mut max_continuation = 0;
    for i in 1..input.s.len() {
        let node = input.s.get(i).unwrap();
        if node.c == '0' {
            let sum = input
                .s
                .get(i - 1..min(i + 2 * input.k as usize, input.s.len()))
                .unwrap_or_default()
                .iter()
                .fold(0, |acc, x| acc + x.n);
            if sum > max_continuation {
                max_continuation = sum;
            }
        } else {
            if node.n > max_continuation {
                max_continuation = node.n;
            }
        }
    }
    Ok(format!("{}", max_continuation))
}

fn main() {
    let mut input_str = String::new();
    let stdin = stdin();
    stdin.lock().read_to_string(&mut input_str).unwrap();
    let input = handle_input(input_str).unwrap();
    let output = handle_output(input).unwrap();
    println!("{}", output);
}

Measured memory_bytes: 4352
// https://atcoder.jp/contests/abc058/tasks/arc071_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll n, p;
string S, m, t;

int main()
{
  cin >> n;
  cin >> m;
  sort(ALL(m));
  REP(i, n - 1)
  {
    cin >> S;
    sort(ALL(S));
    t = "";
    p = 0;
    for (char &c : m)
    {
      if (S.length() <= p)
        break;

      if (c == S[p])
      {
        p++;
        t += c;
      }
      else if (S.find(c) != string::npos && p < S.find(c))
      {
        p = S.find(c) + 1;
        t += c;
      }
    }
    m = t;
  }

  cout << m << '\n';

  return 0;
}


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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, A;
	cin >> N >> A;
	cout << (N%500 <= A ? "Yes" : "No") << endl;
}


Measured memory_bytes: 768
N=int(input())
A=[]
for i in range(0,N):
    a=list(input().split())
    a[0]=float(a[0])
    A.append(a)
sum1=0
for i in range(0,N):
    if A[i][1]=="JPY":
        sum1=sum1+A[i][0]
    else:
        sum1=sum1+A[i][0]*380000.0
print(sum1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  int count=0;
  int result=0;
  cin>>n>>a>>b;
  
  for(int i=1;i<=n;i++){
    int num=i;
    result=0;
    while(num>=1){
      result += num%10;
      num/=10;
    }
    if(a<=result&&result<=b)count+=i;
  }
  
  cout<<count<<endl;
}


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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for(int i = 0; i < n; ++i) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  int ans = 100000000;
  for (int bit = 0; bit < (1<<n); ++bit) {
    vector<int> score(m);
    int price = 0;
    for(int i = 0; i < n; ++i) {
      if( bit & (1<<i)) {
        rep(j, m) score[j] += a[i][j];
        price += c[i];
      }
    }
    bool achieve = true;
    rep(j, m) {
      if(score[j] < x) achieve = false;
    }
    if (achieve) ans = min(ans, price);
  }
  if(ans < 100000000) cout << ans << endl;
  else cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll K;
    cin >> K;
    vector<ll> a(50);
    rep(i,50){
        a[i] = i + (K + 49) / 50;
    }
    ll x = K % 50;
    if (x % 50 != 0){
        rep(i,50 - x){
            a[i]--;
        }
    }
    cout << 50 << endl;
    rep(i,50) cout << a[i] << " ";
    cout << endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

int main(){

	lli n;
	cin>>n;

	vector<lli> a(n);
	map<lli,lli> d;

	REP(i,0,n){
		cin>>a[i];
		d[a[i]]++;
	}

	lli cnt=0;
	for(auto e:d)
	{
		if(e.first<=e.second)cnt += (e.second-e.first);
		else cnt += e.second;
	}
	cout<<cnt<<endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using ll = long long;

    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    rep(i, N)
    {
        int a;
        cin >> a;
        A[i] = make_pair(a, i+1);
    }
    sort(A.begin(), A.end());
    rep(i, N-1)
    {
        cout << A[i].second << " ";
    }
    cout << A[N-1].second << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
  long long W, H, x, y;

  cin >> W >> H >> x >> y;

  double S = W * H / 2.0;

  cout << fixed << showpoint;
  cout << setprecision(10) << S << " " << ((x * 2 == W) && (y * 2 == H) ? '1' : '0') << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,m,tmp,x,sm=0;
  cin >> n;
  map<int,int> mp;
  rep(i,n){
    cin >> tmp;
    sm+=tmp;
    mp[i]=tmp;
  }
  cin >> m;
  rep(i,m){
    cin >> tmp >> x;
    cout << sm-mp[tmp-1]+x << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int ans = 0;
    if (s.equals("SSS"))
      ans = 0;
    if (s.equals("SSR"))
      ans = 1;
    if (s.equals("SRS"))
      ans = 1;
    if (s.equals("SRR"))
      ans = 2;
    if (s.equals("RSS"))
      ans = 1;
    if (s.equals("RSR"))
      ans = 1;
    if (s.equals("RRS"))
      ans = 2;
    if (s.equals("RRR"))
      ans = 3;
    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 35680
import os
import sys

n= map(int, input().split())
a = [x for x in map(int, input().split())]

d = {}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1

ans = 0
for i in d.keys():
    if i > d[i]:
        ans = ans + d[i]
    if i <= d[i]:
        ans = ans + d[i] - i

print(ans)
exit(0) 

Measured memory_bytes: 17780
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD 998244353
#define INF 0x3f3f3f3f
#define MAXN (int)(20)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
ll dp[1<<MAXN];
vll pre;
ll a[MAXN][MAXN];
void solve(int i,vi &cons,int mask,ll &score,int curr_grp)
{
	if(i==cons.size())
	{
		score=max(score,dp[mask]+pre[curr_grp]);
		return;
	}
	int curr_bit=(1<<cons[i]);
	solve(i+1,cons,mask,score,curr_grp);
	solve(i+1,cons,mask^(curr_bit),score,curr_grp^(curr_bit));
}
//dp[mask]-max score if we have grouped rabbits in mask 
//this can be obtained from considering masks st
//some of bits of mask are turned off dp[mask'] and we group the remaining bits
//since mask' is less than mask we would have its answer 
int main()
{
	fastio;
	int n;cin>>n;
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			cin>>a[i][j];
		}
	}
	pre.resize(1<<n);
	//O(2^n * n^2)
	for(int i=0;i<(1<<n);++i)//i is the mask
	{
		for(int j=0;j<n;++j)
		{	
			if(i&(1<<j))
			for(int k=j+1;k<n;++k)
			{
				if((i&(1<<k)))
					pre[i]+=a[j][k];
			}
		}
	}
	dp[0]=0;
	vi cons;
	//O(2^n*n + 3^n)
	for(int mask=0;mask<(1<<n);++mask)
	{
		cons.clear();
		for(int i=0;i<n;i++)
		{
			if((mask & (1<<i)))
				cons.pb(i);
		}
		solve(0,cons,mask,dp[mask],0);
	}
	cout<<dp[(1<<n)-1]<<endl;


}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005,p=1000000007;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,m,L,ans,a[N],po[(1<<16)+5],inv[(1<<16)+5],f[1<<16],g[1<<16];
void check(int &x,int y){if ((x+=y)>=p) x-=p;}
int C(int n,int m){return (n<m) ? 0 : (ll)po[n]*inv[m]%p*inv[n-m]%p;}
int main(){
	n=read();m=read();L=1<<n;
	for (int i=1;i<=m;i++) a[i]=read();
	sort(a+1,a+m+1);
	ans=0;po[0]=1;
	for (int i=1;i<=L;i++) po[i]=(ll)po[i-1]*i%p;
	inv[L]=qpow(po[L],p-2);
	for (int i=L;i;i--) inv[i-1]=(ll)inv[i]*i%p;
	f[0]=1;
	for (int i=m;i;i--){
		for (int j=L-1;j>=0;j--)
		for (int k=0;k<n;k++)
		if (j&(1<<k)) f[j]=(f[j]+(ll)f[j-(1<<k)]*C(L-j+(1<<k)-a[i],(1<<k)-1)%p*po[1<<k])%p;
	}
	for (int i=0;i<L;i++){
		g[i]=g[i>>1]^(i&1);
		check(ans,(g[i]) ? p-(ll)po[L-i-1]*f[i]%p : (ll)po[L-i-1]*f[i]%p);
	}
	ans=(ll)ans*L%p;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl cout<<endl
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
ll n,m,a,b,c,k,x,y,z,ans=0,total=0;
string s;
int main(void){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<fixed<<setprecision(10);
#ifdef FILE_INPUT
  freopen("input.txt","r",stdin);
#endif /// FILE_INPUT
  cin>>n;
  if(n<1000){
    cout<<"ABC"<<endl;
  }else{
    cout<<"ABD"<<endl;
  }
#ifdef FILE_INPUT
#endif /// FILE_INPUT
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<ll>>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
const ll INF = (ll)1e9;

int main(){
    ll n,p;
    cin >> n >> p;
    ll a;
    ll odd=0;
    rep(i,n){
        cin >> a;
        if(a%2)odd++;
    }

    if(!odd){
        if(p) cout << 0;
        else cout << ((ll)1<<n);
    }else{
        cout << ((ll)1<<(n-1));
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;

int calc(int num){
    int s=0;
    while(num != 0){
        s += num % 10;
        num /=10;
    }
    return s;
}


int main(){
    int n;
    cin >> n;
    int sum = calc(n);
    if (n % sum == 0) out("Yes");
    else out("No");

}

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

int c1,c2,a[7][7][7],m,ans;

int main(){
  int i,j,k,l,n,p,x,y,z,ansi;

  while(1){
    cin >> n >> m >> p;
    if(n == 0 && m == 0 && p == 0) break;

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	for(k=0;k<n;k++){
	  a[i][j][k] = 0;
	}
      }
    }

    ansi = 0;

    for(i=0;i<p;i++){
      cin >> x >> y;

      if(ansi != 0) continue;

      x--;
      y--;
      for(j=0;j<n;j++){
	if(a[y][x][j] == 0){
	  a[y][x][j] = i%2 + 1;
	  z = j;
	  break;
	}
      }

      for(int xx=-1;xx<=1;xx++){
	for(int yy=-1;yy<=1;yy++){
	  for(int zz=-1;zz<=1;zz++){
	    if(xx == 0 && yy == 0 && zz == 0) continue;
	    int dx = x + xx;
	    int dy = y + yy;
	    int dz = z + zz;
	    int c = 1;
	    if(dx < 0 || dx >= n || dy < 0 || dy >= n || dz < 0 || dz >= n) continue;

	    if(a[dy][dx][dz] == i%2 + 1){
	      c++;
	      while(1){
		dx += xx;
		dy += yy;
		dz += zz;
		if(dx < 0 || dx >= n || dy < 0 || dy >= n || dz < 0 || dz >= n) break;
		if(a[dy][dx][dz] != i%2 + 1) break;
		c++;
	      }
	    }

	    dx = x - xx;
	    dy = y - yy;
	    dz = z - zz;

	    if(dx >= 0 && dx < n && dy >= 0 && dy < n && dz >= 0 && dz < n){
	      if(a[dy][dx][dz] == i%2 + 1){
		c++;
		while(1){
		  dx -= xx;
		  dy -= yy;
		  dz -= zz;
		  if(dx < 0 || dx >= n || dy < 0 || dy >= n || dz < 0 || dz >= n) break;
		  if(a[dy][dx][dz] != i%2 + 1) break;
		  c++;
		}
	      }
	    }

	    if(c >= m){
	      ansi = i%2 + 1;
	      ans = i + 1;
	      break;
	    }

	  }
	  if(ansi != 0) break;
	}
	if(ansi != 0) break;
      }
    }

    if(ansi == 1) cout << "Black " << ans << endl;
    else if(ansi == 2) cout << "White " << ans << endl;
    else cout << "Draw" << endl;
    
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  int N, M;
  cin >> N >> M;

  vector<P> A(N);
  REP(i,N) cin >> A[i].first >> A[i].second;
  vector<P> B(M);
  REP(i,M) cin >> B[i].first >> B[i].second;

  int check[N] = {0};
  REP(i,N){
    int MIN = INF;
    REP(j,M){
      if(MIN>abs(A.at(i).first-B.at(j).first)+abs(A.at(i).second-B.at(j).second)){
        MIN=abs(A.at(i).first-B.at(j).first)+abs(A.at(i).second-B.at(j).second);
        check[i] = j;
      }
    }
  }

  REP(i,N){
    cout << check[i]+1 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

class Main {
    static final Scanner sc = new Scanner(System.in);
        
    static WeightedUnionFind uf;
    static int n, m;
    static int l, r, d;


    public static void main(String[] args) {
        n = Integer.parseInt(sc.next());
        m = Integer.parseInt(sc.next());

        uf = new WeightedUnionFind(n + 1);

        for (int i = 0; i < m; i++) {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            d = Integer.parseInt(sc.next());

            if (uf.isSameGroup(l, r) &&
                uf.diff(l, r) != d) {
                System.out.println("No");
                return;
            }
            else {
                uf.unite(l, r, d);
            }
        }

        System.out.println("Yes");
    }
}


/**
 * 重み付きUnionFind木.
 * アーベル群まで拡張したいけどパフォが気になるので保留
 * ArrayList\<Integer\>がint[]よりだいぶ遅い
 */
class WeightedUnionFind {
    /** 親を示す 自身が根の場合は -(集合の大きさ) を持つ */
    private int[] parent;
    
    /** ノードの重み (親との差分) */
    private int[] diff_weight;

    public WeightedUnionFind(int nmemb) {
        parent = new int[nmemb];
        diff_weight = new int[nmemb];

        Arrays.fill(parent, -1);
        Arrays.fill(diff_weight, 0);
    }

    /** 根を求める */
    private int root(int x) {
        if (parent[x] < 0) {
            return x;
        }

        // 累積和的に重みを再計算
        int r = root(parent[x]);
        diff_weight[x] += diff_weight[parent[x]];
        parent[x] = r;

        return parent[x];
    }

    private int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    public int diff(int x, int y) {
        return weight(y) - weight(x);
    }
    
    public boolean isSameGroup(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * x->yの重みをwとして併合.
     * 即ち, weight(y) = weight(x) + w が成り立つ
     * x, yが既に同じグループのときは何もしない
     */
    public void unite(int x, int y, int w) {
        if (isSameGroup(x, y)) {
            return;
        }

        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
    
        parent[y] = x;
        diff_weight[y] = w;
    }

    public int groubSize(int x) {
        return -parent[root(x)];
    }
}


Measured memory_bytes: 80136
K = int(input())  #スペース抜きの複数行,１文字ずつ
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A = []
for i in range(1, K + 1):
    for j in range(i, K+1):
        for k in range(j, K + 1):
            if i == j and j == k and k == i:
                #print(i,j,k)
                A.append(gcd_list([i, j, k]))
            elif i != j and j != k and k != i:
                A.append(gcd_list([i, j, k])*6)
            else:
                #print(i,j,k)
                A.append(gcd_list([i, j, k])*3)           

print(sum(A))

Measured memory_bytes: 19828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll a, b, c;
    cin >> a >> b >> c;

    long double s = sqrtl(a*b);
    ll vl = a + b + (ll)(s * 2.0l);
    if(vl < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.IO.Pipes;
using System.ComponentModel;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string Arr = Console.ReadLine();
            int n = Arr.Length;
            long[] l = new long[n + 1];
            long[] r = new long[n + 1];
            long ans = 0;
            for (int i = 0; i < n; i++) 
            {
                if (Arr[i] == '<') 
                {
                    l[i + 1] = l[i] + 1;
                }
            }
            for (int i = n-1; i >= 0 ; i--)
            {
                if (Arr[i] == '>')
                {
                    r[i] = r[i+1] + 1;
                }
            }
            for (int i = 0; i < n+1; i++)
            {
                ans += Math.Max(r[i], l[i]);
            }
            Console.WriteLine(ans);
        }

    }
}


Measured memory_bytes: 35664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    string s;cin>>s;
    v pre(n),suf(n);
    for(int i=0;i<n;i++)
    {
    	if(i!=0)
    		pre[i]=pre[i-1];
    	if(s[i]=='W')
    		pre[i]++;
    }
    for(int i=n-1;i>=0;i--)
    {
    	if(i!=(n-1))
    		suf[i]=suf[i+1];
    	if(s[i]=='R')
    		suf[i]++;
    }
    int ans=min(suf[0],pre[n-1]);
    for(int i=0;i<n-1;i++)
    	ans=min(ans,max(pre[i],suf[i+1]));
    cout<<ans<<endl;
    return 0;
}

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

template <class T>
inline vector<T> vec(size_t n, T a) {
  return vector<T>(n, a);
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto& e : s) cin >> e;

  auto dp = vec(h, vec(w, vec(2, (int)1e9)));
  dp[0][0][s[0][0] == '#'] = s[0][0] == '#';

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int k = s[i][j] == '#';
      if (i - 1 >= 0) dp[i][j][k] = min({dp[i][j][k], dp[i - 1][j][0] + k, dp[i - 1][j][1]});
      if (j - 1 >= 0) dp[i][j][k] = min({dp[i][j][k], dp[i][j - 1][0] + k, dp[i][j - 1][1]});
    }
  }

  cout << min(dp[h - 1][w - 1][0], dp[h - 1][w - 1][1]) << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    REP(i, N) {
        cin >> x[i];
    }
    REP(i, M) {
        cin >> y[i];
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    int maxX = x[N-1];
    int minY = y[0];

    if(X >= Y) {
        print("War");
        return 0;
    }
    vector<int> Z;
    for(int i=X+1; i<=Y; i++) {
        Z.push_back(i);
    }

    bool found = false;
    REP(i, Z.size()) {
        int z = Z[i];
        if (maxX < z && z <= minY) {
            found = true;
            break;
        }
    }

    if(found) {
        print("No War");
    } else {
        print("War");
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

void mod(vector<long long>& a, int m){
	for(auto& i : a) i %= m;
}

int main(){
	long long n, m;
	cin >> n >> m;

	vector<long long> a(n, 0);
	rep(i,n) cin >> a[i];

	rep(i,a.size() - 1) a[i + 1] += a[i];

	map<long long,long long> b;
	rep(i,a.size()) b[a[i] % m]++;

	long long ans = 0;
	for(auto i : b){
		ans += i.second * (i.second - 1) / 2;
	}
	cout << ans + b[0] << endl;
}


Measured memory_bytes: 4992