akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, ans, x;
ll a[111111];

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int i; cin>>n>>x;
	for(i=1 ; i<=n ; i++)
	{
		cin>>a[i];
		if(a[i]>x) ans+=(a[i]-x);
		if(a[i]>x) a[i]=x;
	}
	for(i=1 ; i<n ; i++)
	{
		if(a[i]+a[i+1]>x) ans+=(a[i]+a[i+1]-x);
		if(a[i]+a[i+1]>x) a[i+1]=x-a[i];
	}
	cout<<ans; return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli k, t;

int main(void){
    cin >> k >> t;
    vector<lli> a(t);
    rep(i, t) cin >> a[i];
    sort(a.begin(), a.end());
    vector<lli> s(t+1);
    rep(i, t) s[i+1] = s[i]+a[i];
    lli x, y, d;
    d = 1e9;
    rep(i, t+1){
        if(abs(2*s[i]-s[t]) < d){
            d = abs(2*s[i]-s[t]);
            x = s[i];
            y = s[t]-s[i];
        }
    }
    cout << max(0LL, abs(x-y)-1) << endl;
    return 0;
}


Measured memory_bytes: 3596
while True:
    cards=input()
    if cards == "-":
        break
    m = int(input())
    lit=[]
    for i in range(m):
        del lit[:]
        cards=(''.join(cards))
        for aa in cards:
            lit.append(aa)
        cards=list(cards)
        h=int(input())
        for j in range(h):
            cards.remove(cards[0])
            cards.append(lit[j])
    print( "".join(cards) )


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  string n;
  cin >> n;
  ll result = 5000;
  for(i = 0; i < n.size() - 2; i++)
    chmin(result, abs(753 - (100 * (n[i] - '0') + 
                              10 * (n[i + 1] - '0') + n[i + 2] - '0')));
  cout << result << endl;

  return 0;
}

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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a, b;
	cin >> a >> b;

	if(a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               int a,b;
               cin>>a>>b;
               if(a>0)
                    cout<<"Positive";
               else if(a<=0 && b>=0)
                    cout<<"Zero";
               else
               {
                    if(a<0 && b==0)
                    {
                         a = abs(a);
                         if(a%2)
                              cout<<"Negative";
                         else
                              cout<<"Positive";
                    }
                    else
                    {
                         a = abs(a);
                         b = abs(b);
                         int ans = a-b;
                         if(ans%2)
                              cout<<"Positive";
                         else
                              cout<<"Negative";
                    }
               }
       }
}


Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int map[30][10];
int n, d, m, goal;

bool ok() {
	int pos = m-1;
	for(int y = 0; y < d; y++) {
		if(pos < d-1 && map[y][pos]) pos++;
		else if(pos > 0 && map[y][pos-1]) pos--;
	}
	//cout << pos << endl;
	if(pos == goal-1) return true;
	return false;
}

bool write(int y,int x) {
	if(map[y][x] == 1) return false;
	if((x < d-1 && map[y][x+1] == 0) || x == d-1) {
		if((0 < x && map[y][x-1] == 0) || x == 0) {
			return true;
		}
	}
	return false;
}

int main(void)
{
	while(1) {
		cin >> n;
		if(n == 0) break;
		cin >> m >> goal >> d;
		
		for(int y = 0; y < 30; y++) for(int x = 0; x < 10; x++) map[y][x] = 0;
		
		string str;
		for(int y = 0; y < d; y++) {
			cin >> str;
			for(int x = 0; x < n-1; x++) {
				map[y][x] = str[x] - '0';
			}
		}
		
		if(ok()) {
			cout << 0 << endl;
			continue;
		}
		
		bool clear = false;
		for(int y = 0; y < d && !clear; y++) {
			for(int x = 0; x < n-1 && !clear; x++) {
				if(write(y,x)) {
					map[y][x] = 1;
					if(ok()) {
						cout << y+1 << " " << x+1 << endl;
						clear = true;
					}
					map[y][x] = 0;
				}
			}
		}
	
		if(!clear)  cout << 1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int M1, D1, M2, D2; cin >> M1 >> D1 >> M2 >> D2;
  if(D2==1) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,ans=1e9,l[N],r[N],mx[N];
char a[N],b[N];
void work() {
    for(int i=0;i<n;i++) {
        l[i]=r[i]=0;
        while(b[(i+r[i])%n]!='1') ++r[i];
        while(b[(i+l[i]+n)%n]!='1') --l[i];
    }
    for(int s=0;s<n;s++) {
        for(int i=0;i<n;i++) mx[i]=0;
        int dif=0;
        for(int i=0;i<n;i++)
            if(a[i]!=b[(i+s)%n])
                mx[-l[i]]=max(mx[-l[i]],r[i]-s),++dif;
        int mn=1e9,y=0;
        for(int x=n-1;x>=0;x--)
            mn=min(mn,x+y),y=max(y,mx[x]);
        ans=min(ans,2*mn+s+dif);
    }
}
int main() {
    scanf("%s",a),scanf("%s",b),n=strlen(a);
    int A=0,B=0;
    for(int i=0;i<n;i++) {
        if(a[i]=='1') ++A;
        if(b[i]=='1') ++B;
    }
    if(!B) {
        if(!A) puts("0");
        else puts("-1");
        return 0;
    }
    work();
    reverse(a,a+n),reverse(b,b+n);
    work();
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int m=a.length(),n=b.length();
    int ar[m+1][n+1];
    for(int i=0;i<m+1;++i){ar[i][0]=0;}
    for(int i=0;i<n+1;++i){ar[0][i]=0;}
    for(int i=1;i<m+1;++i)
    {
        for(int j=1;j<n+1;++j)
        {
            if(a[i-1]==b[j-1]){ar[i][j]=ar[i-1][j-1]+1;}
            else{ar[i][j]=max(ar[i-1][j],ar[i][j-1]);}
            //cout<<ar[i][j]<<" ";
        }
        //cout<<endl;
    }
    int i=m,j=n;
    string ans;
    while(i>0 && j>0)
    {
        //cout<<i<<" "<<j<<endl;
        if(a[i-1]==b[j-1]){ans.push_back(a[i-1]);i--;j--;}
        else{
            if(ar[i-1][j]>ar[i][j-1]){i--;}
            else{j--;}
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}


Measured memory_bytes: 38732
def resolve():
    N = int(input())
    L = list(map(int, input().split()))
    cnt = 0
    import itertools
    for x, y, z in itertools.combinations(L, 3):
        if x != y and y != z and z != x:
            M = max(x, y, z)
            if M < sum([x, y, z]) - M:
                cnt += 1
    print(cnt) 

    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 68864
// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
#include <bits/stdc++.h>
using namespace std;
// ¯\_(ツ)_/¯
#define f first
#define s second
#define p push
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define foi(i, a, n) for (i = (a); i < (n); ++i)
#define foii(i, a, n) for (i = (a); i <= (n); ++i)
#define fod(i, a, n) for (i = (a); i > (n); --i)
#define fodd(i, a, n) for (i = (a); i >= (n); --i)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005
#define MOD 1000000007LL
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18
// ¯\_(ツ)_/¯
#define l long int
#define d double
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
//vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.
#define mii map<int, int>
#define mll map<long long, long long>
#define pii pair<int, int>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;




int main()
{
    fast_io();
#ifndef ONLINE_JUDGE
    //freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
#endif

    cin>>n;
    vll height(n, 0);
    rep(i, 0, n) cin>>height[i];
    vll step = {1, 2};
    vll dp(n, INT_MAX);
    dp[0] = 0;
    rep(i, 0, n) {
        rep(j, 0, sz(step)) {
            if(i - step[j] >= 0) {
                dp[i] = min(dp[i], abs(height[i] - height[i-step[j]])  + dp[i-step[j]]);
            }
        }
    }
    cout<<dp[n-1];


    return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
double Pi = 3.141592653589793238;
using namespace std;
using Graph = vector<vector<ll>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//

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

	cout <<a*b<< endl;

	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N,D;
  cin>>N>>D;
  vector<vector<int>> X(N,vector<int>(D,0));

  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>X[i][j];
    }
  }

  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int dist=0;
      for(int k=0;k<D;k++){
        dist+=pow(X[i][k]-X[j][k],2);
      }
      if(dist==(int)sqrt(dist)*(int)sqrt(dist)) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, q, a, b; string s;
int main() {
	while (cin >> n >> q, n | q) {
		set<int> d;
		for (int i = 0; i < q; i++) {
			cin >> s >> a >> b;
			for (int j = 1; j <= n; j++) {
				if (s == "xy") d.insert(a * n * n + b * n + j);
				if (s == "xz") d.insert(a * n * n + j * n + b);
				if (s == "yz") d.insert(j * n * n + a * n + b);
			}
		}
		cout << n * n * n - d.size() << endl;
	}
}

Measured memory_bytes: 5476
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] a = nextIntArray(sc, N);

		sc.close();

		int[] colors = new int[8];
		int oth = 0;

		for (int i = 0; i < N; i++) {
			if (a[i] <= 399) {
				colors[0]++;
			} else if (a[i] <= 799) {
				colors[1]++;
			} else if (a[i] <= 1199) {
				colors[2]++;
			} else if (a[i] <= 1599) {
				colors[3]++;
			} else if (a[i] <= 1999) {
				colors[4]++;
			} else if (a[i] <= 2399) {
				colors[5]++;
			} else if (a[i] <= 2799) {
				colors[6]++;
			} else if (a[i] <= 3199) {
				colors[7]++;
			} else {
				oth++;
			}
		}

		int cnt = 0;
		for (int i = 0; i < 8; i++) {
			if (colors[i] != 0) {
				cnt++;
			}
		}

		int ansMin, ansMax;
		if (cnt == 0) {
			ansMin = 1;
		} else {
			ansMin = cnt;
		}

		ansMax = cnt + oth;

		out.print(ansMin);
		out.print(" ");
		out.println(ansMax);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 21844
#include <deque>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;

int parent[200005][2];
map<pair<int, int>, int> mp;

int find(int x, int i)
{
	if (parent[x][i] != x)
		parent[x][i] = find(parent[x][i], i);
	return parent[x][i];
}

void merge(int x, int y, int i)
{
	x = find(x, i);
	y = find(y, i);
	if (x != y)parent[x][i] = y;
}


int main()
{
	int N, K, L;
	cin >> N >> K >> L;
	for (int i = 1; i <= N; i++)
		parent[i][0] = parent[i][1] = i;
	while (K--) {
		int u, v;
		cin >> u >> v;
		merge(u, v, 0);
	}
	while (L--) {
		int u, v;
		cin >> u >> v;
		merge(u, v, 1);
	}
	for (int i = 1; i <= N; i++)
		mp[{find(i,0),find(i,1)}]++;
	for (int i = 1; i <= N; i++) {
		cout << mp[{find(i, 0), find(i, 1)}] << ' ';
	}
}

Measured memory_bytes: 13568
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

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

    if (a > b) swap(a, b);
    if (c > a && c < b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

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

    string s;
    cin >> s;

    cout << 700 + 100 * (int)count(s.begin(), s.end(), 'o') << endl;



    return 0;
}

Measured memory_bytes: 256
def diff(a)
  [a / 2, a - a/2].max - [a / 2, a - a/2].min
end

a, b, c = *$stdin.read.split.map(&:to_i)
res = []
res << diff(a) * b * c if a > 1
res << diff(b) * a * c if b > 1
res << diff(c) * a * b if c > 1
puts res.min

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<ll,ll>;
//const int 1001001001;
const int NMAX=8;
const ll MOD=1000000007;
const ll INF=1e18;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  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;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { 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;}


mint calc(ll a, ll b, ll c, ll d){
	mint ans=0;

	mint a1=mint(2).pow(a);
	mint b1=mint(2).pow(b);
	mint c1=mint(2).pow(c);
	mint d1=mint(2).pow(d);

	ans+=(a1-1)*b1*(c1-1)*d1;
	ans+=a1*(b1-1)*c1*(d1-1);
	ans-=(a1-1)*(b1-1)*(c1-1)*(d1-1);
	ans+=a1*b1*c1*d1;

	return ans;
}

vector<P> v(200005);
vector<ll> g[200005];
vector<bool> used(200005);
mint ans=0;

mint dfs(ll v){
	used[v]=true;
	mint res=1;
	for(ll u:g[v]){
		if (used[u])continue;
		//vが残っている場合、下はなんでも
		res*=dfs(u);
	}
	//vがないとき、下は全部なし
	res+=1;
	//cout<<v<<'v'<<res<<'r'<<endl;
	return res;
}


int main(){
	ll n;
	cin>>n;
	v.resize(n);
	rep(i,n){
		cin>>v[i].first>>v[i].second;

	}
	sort(v.begin(),v.end());
	vector<P> t;//一時的に座標大きい順に入れていく
	for(ll i=n-1;i>=0;i--){
	//	cout<<v[i].first<<' '<<v[i].second;
	//	cout<<t.size()<<endl;
		if (t.size()==0){
			t.push_back(P(v[i].first,i));
			continue;
		}
		else{
			while(t.size()>0){
				P now=t.back();
				if ((v[i].first+v[i].second)<=now.first)break;
			//	cout<<v[i].first<<'f'<<v[i].second<<'s'<<now.first<<'n'<<endl;
				if ((v[i].first+v[i].second)>now.first){
					g[i].push_back(now.second);
					//cout<<i<<'i'<<now.second<<endl;
					t.pop_back();
				}
			}
			t.push_back(P(v[i].first,i));
		}
	}

	mint ans=1;

	rep(i,n){
		if (used[i])continue;
		ans*=dfs(i);

	}
	cout<<ans;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#include <queue>
#define INF LONG_MAX
typedef long long ll;
struct edge{ll to, cost;};
typedef pair<ll,ll> P;

struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    for(int i = 0; i < V; i++){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    for(int i = 0; i < V; i++){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

/*
graph g(n);

と書けばn頂点のグラフが作成され、

  g.add_edge(a,b,cost);

とすれば頂点aから頂点bへのコストcostの辺が張られます。そして

  g.dijkstra(s);

とすれば頂点sから各頂点への最短経路をダイクストラ法で探索できます。探索結果は

  int dist = g.d[i]:

と呼び出して使うことができます。
*/

int main(){
  ll n,m,s,t;
  cin >> n >> m >> s >> t;
  graph g_en(n);
  graph g_nuuk(n);

  rep(i,m){
    ll to, from, en_cost, nuuk_cost;
    cin >> to >> from;
    cin >> en_cost >> nuuk_cost;
    to--, from--;

    g_en.add_edge(to,from,en_cost);
    g_en.add_edge(from,to,en_cost);

    g_nuuk.add_edge(to,from,nuuk_cost);
    g_nuuk.add_edge(from,to,nuuk_cost);
  }

  s--, t--;
  g_en.dijkstra(s);
  g_nuuk.dijkstra(t);

  VLL ans(n+1);
  ans[n] = 1e15;
  for(int i = n-1; i >= 0; i--){
    ans[i] = min(ans[i+1], g_en.d[i] + g_nuuk.d[i]);
  }

  rep(i,n) cout << (ll)1e15 - ans[i] << endl;

  return 0;
}


Measured memory_bytes: 19012
N, K = [int(i) for i in input().split(' ')]
MOD = 10 ** 9 + 7

COUNT = {}
for i in range(K,0,-1):
    whole = pow((K//i), N, MOD)

    c = 2
    while i * c <= K:
        whole -= COUNT[i*c]
        c += 1

    COUNT[i] = whole % MOD

SUM = 0
for k, v in COUNT.items():
    SUM += k * v
    SUM %= MOD

print(SUM)


Measured memory_bytes: 20680
#include<iostream>
#include<cstdio>
#include<complex>
#include<algorithm>
#include<cmath>
using namespace std;

#define rep(i, n) for ( int i = 0; i < n; i++ )
#define REP(i, b, e) for ( int i = b; i <= e; i++ )
#define MAX 40
typedef complex<double> Point;
int n, m;
double P[MAX];
static const double PI = acos(-1.0);

double getArea(double r1, double r2, double r3){
    Point p1 = polar(1.0, r1*2*PI);
    Point p2 = polar(1.0, r2*2*PI);
    Point p3 = polar(1.0, r3*2*PI);
    double a = abs(p1 - p2);
    double b = abs(p2 - p3);
    double c = abs(p3 - p1);
    double s = (a + b + c)/2.0;
    return sqrt(s*(s-a)*(s-b)*(s-c));
}

void compute(){
    double M[MAX+1][MAX][MAX];
    double T[MAX][MAX][MAX];
    rep(i, n) rep(j, n) rep(k, n) T[i][j][k] = getArea(P[i], P[j], P[k]);
    double maxv = 0.0;
    rep(k, m+1) rep(i, n) rep(j, n) M[k][i][j] = 0.0;
    REP(k, 2, m-1){
	REP(i, 0, n-2) REP(j, i+1, n-1){
	    int t = (j+1)%n;
	    while(1){
		if ( t == i ) break;
		M[k+1][i][t] = max(M[k+1][i][t], M[k][i][j] + T[i][j][t]);
		t = (t+1)%n;
	    }
	}
    }
    rep(i, n) rep(j, n) maxv = max(maxv, M[m][i][j]);
    printf("%.6lf\n", maxv);
}

main(){
    while(1){
	scanf("%d %d", &n, &m);
	if ( n == 0 && m == 0 ) break;
	rep(i, n) scanf("%lf", &P[i]);
	compute();
    }
}

Measured memory_bytes: 0
k, s = map(int, input().split())
diff = 3 * k - s
ans = 0
low = max(0, k - diff)
for x in range(low, k + 1):
    for y in range(low, k + 1):
        if k >= s - x - y and s - x - y >= 0:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<limits.h>

using namespace std;

int main(void) {
	long long N, T;
	cin >> N >> T;
	vector<long long> t(N);
	
	for (int i = 0; i < N; i++) cin >> t[i];

	long long ans = T;
	for (int i = 0; i < N - 1; i++) {
		ans += min(T, t[i + 1] - t[i]);
	}

	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
  vector<int>
      sizes; // sizes[i]:根iの木に含まれるデータの数、根でない場合は無意味な値となる

  UnionFind(int N) : par(N), sizes(N, 1) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if(rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま
    if(sizes[rx] < sizes[ry]) swap(rx, ry); // xの木 > yの木にする
    par[ry] =
        rx; // xとyの根が同じでない(=同じ木にない)時：yの根ryをxの根rxにつける
    sizes[rx] += sizes[ry];
    sizes[ry] = 0; // 一応0にしておく
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int size(int x) { // データxが含まれる木の大きさを返す
    return sizes[root(x)];
  }
};

struct Edge {
  ll from, to, cost;
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll V, E;
  cin >> V >> E;
  vector<Edge> edges(E);
  REP(i, E) {
    int s, t, w;
    cin >> s >> t >> w;
    edges[i] = {s, t, w};
  }
  sort(all(edges),
       [](const Edge &x, const Edge &y) { return x.cost < y.cost; });
  UnionFind uf(V);
  int ans = 0;
  REP(i, E) {
    Edge e = edges[i];
    if(!uf.same(e.from, e.to)) {
      uf.unite(e.from, e.to);
      ans += e.cost;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5428
import Data.List

main = do
  secondStr <- getLine
  putStrLn $ concat . intersperse ":" . map show . convertSecond $ read secondStr

convertSecond :: Int -> [Int]
convertSecond second = let hour = second `div` 3600
                           minite = (second `mod` 3600) `div` 60
                           sec = (second `mod` 3600) `mod` 60
                       in hour:minite:sec:[]

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
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; }

int main(){
	ll a, b, c, d;
	std::cin >> a >> b >> c >> d;
	ll res = a * c;
	chmax(res, a * d);
	chmax(res, b * c);
	chmax(res, b * d);
	std::cout << res << std::endl;
	return 0;
}

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

int N,M;
int q[100005];
int p[100005];

const int MAX = (1<<17);
struct seg {
  int d[2*MAX];
  int n = 0;
  void init(int _n){
    memset( d,0,sizeof(d) );
    n = 1;
    while( n < _n ) n*=2;
  }
  void set(int k,int x){
    k += n-1;
    d[k] = x;
    while( k ){
      k = (k-1)/2;
      d[k] = max( d[2*k+1], d[2*k+2] );
    }
  }
  int query(int a,int b,int k,int l,int r){
    if( r <= a || b <= l ) return 0;
    else if( a <= l && r <= b ) {
      return d[k];
    } else {
      int vl = query( a, b, 2*k+1, l, (l+r)/2 );
      int vr = query( a, b, 2*k+2, (l+r)/2, r );
      return max( vl, vr );
    }
  }
  int query(int a,int b){
    return query( a, b, 0, 0, n );
  }

};

seg S;
void rev(){
  for(int i = 0; i < N; i++ )
    q[i] = N-q[i];
}
int check(int id,int k,int f){
  if( id >= N ) return N;
  if( f == -1 ) rev();
  S.init(N);
  for(int i=id;i<N;i++){
    int x = S.query( 0, q[i] );
//    cout << i << " " <<q[i] << " "<<  x << endl;
    x++;
    S.set( q[i], x );
  //  cout << i << ": " << x << endl;
    if(x == k) {
      if( f == -1 ) rev();
      return i;
    }
  }
  if( f == -1 ) rev();
  return N;
}

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

  if( N == 1 && M ==1  ){
    cout << "Yes" << endl;
    return 0;
  }

  int id = 0;
  int k = 2;
  int f = (p[1]-p[0])<0?-1:1;
  for(int i=1;i<M-1;i++){
    int nf = (p[i+1]-p[i])<0?-1:1;
    if( nf != f ){
  //    cout << id << " " <<k << " "<< f << endl;
      id = check( id, k, f );
      k = 2; f = nf;
    } else {
      k++;
    }
  }
//  cout << id << " "<< k <<" " << f << endl;
  id = check( id, k, f );
  if( id >= N ) cout << "No" << endl;
  else cout << "Yes" << endl;


}

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];
    vector<int> memo(n);
    for(int i = 0; i < n; i++) memo[i] = x[i];
    sort(memo.begin(), memo.end());

    for(int i = 0; i < n; i++){
        int left = -1;
        int right = n;
        int mid;
        do{
            mid = (left + right)/2;
            if(memo[mid] == x[i]) break;
            else if(memo[mid] < x[i]) left = mid+1;
            else right = mid-1;
        }while(right > left);

        if(mid >= n/2) cout << memo[n/2-1] << endl;
        else cout << memo[n/2] << endl;
    }
    return 0;
}

Measured memory_bytes: 4812
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int H, W; cin >> H >> W;
	if (H == 1 || W == 1) cout << 1 << endl;
	else cout << (((ll)H * W + 1) / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 10;
const int mod = 998244353;
char s[N];
int main() {
	scanf("%s", &s);
	for (int i = 0; s[i]; i++)if (s[i] == '?')s[i] = 'D';
	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 3844
using System;
using System.Collections.Generic;
using System.Linq;

class className
{
    static int n, r;

    static void Solve()
    {
        var internalRating = n >=10 ? r : r + 100 * ( 10 - n );
        System.Console.WriteLine(internalRating);
    }

    static void Scan()
    {
        var buf = Console.ReadLine().Split();
        n = int.Parse(buf[0]);
        r = int.Parse(buf[1]);
    }

    static void Main()
    {
        Scan();
        Solve();
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	long long int n, k;
	cin >> n >> k;
	vector<long double> s;
	s.push_back(0);
	for (int i = 1; i <= n; i++) {
		long double a;
		cin >> a;
		s.push_back((a+1)/2 + s[i-1]);
	}
/*	for (int i = 0; i <= n; i++) {
		cout << s[i]<<endl;
	}
	*/
	long double kotae = 0;
	for (int i = k; i <= n; i = i + 1) {
		kotae = max(kotae, s[i] - s[i - k]);
	}
	cout << fixed<<setprecision(20)<<kotae;
}


Measured memory_bytes: 6128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	ll s; cin >> s;
	ll x1, y1, x2, y2, x3, y3;
	x1 = 0;
	y1 = 0;
	x2 = 1e9;
	x3 = 1;
	if (s <= 1e9) {
		y3 = 1;
		y2 = x2 - s;
	}
	else {
		if (s%x2 == 0) {
			y3 = s / x2;
			y2 = 0;
		}
		else {
			y3 = s / x2 + 1;
			y2 = x2 * y3 - s;
		}
	}
	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[])
{
    int x;
    set<int> st;
    for (int i = 0; i < 3; i++)
    {
        cin >> x;
        st.insert(x);
    }

    if (st.size() == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<cmath>
#include<map>
#define fs first
#define sc second
#define EPS (1e-10)
using namespace std;


typedef complex<double> P;
typedef pair<P,double> C;

int cpr(C a,C b){
  double d = abs(a.fs-b.fs);
  if(a.sc+b.sc + EPS < d)return -1;      //no intersection (outside)
  if(b.sc<a.sc && d + EPS < a.sc-b.sc)return 1;       //no intersection (inside,B in A)
  if(a.sc<b.sc && d + EPS < b.sc-a.sc)return 2;       //no intersection (inside,A in B)
  if(abs(a.sc+b.sc - d) < EPS)return -3; //one cross point (outside)
  if(abs(b.sc+d - a.sc) < EPS)return 3;  //one cross point (inside,B in A)
  if(abs(a.sc+d - b.sc) < EPS)return 4;  //one cross point (inside,A in B)
  return 0;                              //two cross point
}


int main(){
  double ax,ay,ar,bx,by,br;

  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin>> ax >> ay >> ar >> bx >> by >> br;
    C a = C(P(ax,ay),ar), b = C(P(bx,by),br);
    int v = cpr(a,b);
    if(v==-1)cout <<  0 << endl;
    else if(v==1)cout << 2 << endl;
    else if(v==2)cout << -2 << endl;
    else cout << 1 << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	vector<int>c(n-1);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n - 1) {
		cin >> c[i];
	}
	ll sum(0);
	int buffer(-1);
	rep(i, n) {
		if (a[i] == buffer+1) {
			sum+=c[a[i]-2];
		}
		sum += b[a[i]-1];
		buffer = a[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int ans = 1;
  for(int i=0;i<N;i++){
  	ans = min(ans*2, ans+K);
  }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int from = b-(a-1);
		int to = b+(a-1);
		for (int i = from; i <=to; i++) {
			System.out.print(i+" ");
		}

	}

}


Measured memory_bytes: 21588
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
const int Max = 100 + 5;
int n, m;
char g[Max][Max];
int ans = 0;
int dx[5] = {0, 1, 0, -1, 0};
int dy[5] = {0, 0, 1, 0, -1};
void dfs(int x, int y, char ch) {
    g[x][y] = '0';
    for (int i = 1; i <= 4; i++) {
        int xx = x + dx[i], yy = y + dy[i];
        if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && g[xx][yy] == ch)
            dfs(xx, yy, ch);
    }
}
int main() {
    while(scanf("%d %d", &n, &m) == 2 && n && m) {
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                cin >> g[i][j];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if(g[i][j] != '0') {
                    dfs(i, j, g[i][j]);
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
        ans = 0;
    }
    return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define emp emplace
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 200100;
const ll INF = 1e9;
const ll MOD = 1e9+7;

ll N,Q,a,b,c,d,e,T,M;
ll A[MAXN];
ll B[MAXN];
typedef pair<pi,pi> pp;
vector<pp> V;
vi cur;
ll ans;

void ask(){
	if(SZ(cur) == N){

		ll L=0;
		for(auto i:V){
			if(abs(cur[i.f.f] - cur[i.f.s]) == i.s.f)L += i.s.s;
		}
		ans=max(ans,L);
		return;
	}
	int b = 1;
	if(SZ(cur))b=cur.back();
	for(int i=b;i<=M;++i){
		cur.pb(i);
		ask();
		cur.pop_back();
	}
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>N>>M>>Q;
	for(int i=0;i<Q;++i){
		cin>>a>>b>>c>>d;
		--a;--b;
		V.pb(mp(a,b),mp(c,d));
	}
	ask();
	cout<<ans;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long a[200000], b[200000];
int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	if (N % 2 == 0) {
		for (int i = N - 1; i >= 0; i -= 2) {
			printf("%lld ", a[i]);
		}
		for (int i = 0; i < N; i += 2) {
			printf("%lld ", a[i]);
		}
	}
	else {
		for (int i = N - 1; i >= 0; i -= 2) {
			printf("%lld ", a[i]);
		}
		for (int i = 1; i < N; i += 2) {
			printf("%lld ", a[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <ctime>
#include <numeric>
#include <fstream>
#include <valarray>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const long double pi=acos(-1.0);
int dx[]={0,1,0,-1,1,1,-1,-1,0},dy[]={1,0,-1,0,1,-1,1,-1,0};

int st[14][14];
bool vis[14][14];
bool out[14][14];
int n,c;

int tx[]={-1,-1,0,0,1,1};
int ty[]={-1,0,-1,1,0,1};

bool check0(int x,int y){
  if(vis[x][y])return false;
  vis[x][y]=true;
  rep(i,6){
    int nx=x+tx[i],ny=y+ty[i];
    if(st[nx][ny]==0 ||
       st[nx][ny]==st[x][y] && check0(nx,ny))
      return true;
  }
  return false;
}

void dfs(int x,int y){
  if(st[x][y]==-1 || out[x][y])return;
  out[x][y]=true;
  rep(i,6){
    int nx=x+tx[i],ny=y+ty[i];
    if(st[nx][ny]==st[x][y])
      dfs(nx,ny);
  }
}

int sim(){
  memset(out,0,sizeof(out));
  memset(vis,0,sizeof(vis));

  rep(i,n)rep(j,i+1){
    if(out[i+1][j+1] || !st[i+1][j+1])continue;
    memset(vis,0,sizeof(vis));
    if(!check0(i+1,j+1))
      dfs(i+1,j+1);
  }
  int ret=0;
  rep(i,n)rep(j,i+1)
    if(out[i+1][j+1])
      ret+=(st[i+1][j+1]==c?-1:1);
  return ret;
}


void solve(){
  memset(st,-1,sizeof(st));
  rep(i,n)
    rep(j,i+1)cin>>st[i+1][j+1];

  int ans=-n*n;

  rep(i,n)
    rep(j,i+1){
    if(st[i+1][j+1])continue;
    st[i+1][j+1]=c;
    ans=max(ans,sim());
    /*
    rep(k,n){
      rep(l,k+1)
        cout<<st[k+1][l+1]<<out[k+1][l+1]<<' ';
        cout<<endl;
    }
    */
    st[i+1][j+1]=0;
  }
  cout<<ans<<endl;
  //exit(0);
}

main(){
  while(cin>>n>>c,n|c)
    solve();
}

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

	int z, k;
	char A, B, C;
	char string[55];
	
	scanf("%d %d", &z, &k);
	getchar();
	scanf("%s", &string);
	
	string[k-1] += 32;
	printf("%s", string);
	return 0;
}



Measured memory_bytes: 1700
#include <stdio.h>
int N, M, Q;
int a[50], b[50], c[50], d[50];
int A[10];
int i, j;
int ans;
int main () {
    scanf("%d%d%d", &N, &M, &Q);
    N--, M--;
    for (i = 0; i < Q; i++) {
        scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--, b[i]--;
    }
    while (1) {
        int res = 0;
        for (i = 0; i < Q; i++) {
            if (A[b[i]]-A[a[i]] == c[i]) res += d[i];
        }
        if (ans < res) ans = res;
        if (A[0] == M) break;
        for (i = N;; i--) {
            if (A[i] < M) {
                A[i]++;
                for (j = N; j > i; j--) {
                    A[j] = A[i];
                }
                break;
            }
        }
    }
    printf("%d", ans);
}

Measured memory_bytes: 1728
#include<stdio.h>
int main(){
   int n,ans,y;
   scanf("%d",&n);
   ans=n;
   y=ans%10;
   if(y==2||y==4||y==5||y==7||y==9){
      printf("hon");
   }else if(y==0||y==1||y==6||y==8){
      printf("pon");
   }else{
      printf("bon");
      
   }
   return 0;
}
   


Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=100005;
int n,m,tot,js,Q;
int h[N],ne[N<<1],to[N<<1],wk[N],X[N],D[N],C[N],col[N],q[N],dis[N];
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
void work(int x,int d,int c) {
	if(d<=wk[x]) return;
	wk[x]=d;
	if(!col[x]) col[x]=c;
	if(!d) return;
	for(RI i=h[x];i;i=ne[i]) work(to[i],d-1,c);
}
int main()
{
	int x,y;
	n=read(),m=read();
	for(RI i=1;i<=m;++i) x=read(),y=read(),add(x,y),add(y,x);
	Q=read();
	for(RI i=1;i<=Q;++i) X[i]=read(),D[i]=read(),C[i]=read();
	for(RI i=1;i<=n;++i) wk[i]=-1;
	for(RI i=Q;i>=1;--i) work(X[i],D[i],C[i]);
	for(RI i=1;i<=n;++i) printf("%d\n",col[i]);
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }

const int MAXN = 2000;
const ll _MAX_ = 1e17;

int N, M;
struct Edge {
    int u, v;
    ll c;
};

vector<Edge> edges;
ll dist[MAXN];

int main() {
    FAST_IO();
    cin >> N >> M;
    rep(i, M) {
        Edge e; cin >> e.u >> e.v >> e.c;
        e.u--; e.v--;
        e.c = -e.c;
        edges.push_back(e);
    }
    // Bellman-Ford
    rep(i, N) dist[i] = _MAX_;
    dist[0] = 0;
    rep(i, N) {
        for(auto &e : edges) {
            ll tmp = dist[N-1];
            if(dist[e.u] != _MAX_ && dist[e.v] > dist[e.u] + e.c) {
                dist[e.v] = dist[e.u] + e.c;
                if(i == N - 1 && dist[N - 1] < tmp) {
                    cout << "inf\n";
                    return 0;
                }
            }   
        }
    }   
    cout << -dist[N-1] << "\n";
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	if (A == B){
		printf("%d", C);
	}
	else if (A == C){
		printf("%d", B);
	}
	else{
		printf("%d", A);
	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    FOR(i, 0, n){
        cin >> s[i];
    }
    
    int q;
    cin >> q;
    vector<int> t(q);
    int cnt=0;
    FOR(i, 0, q){
        cin >> t[i];
        if ( *lower_bound(s.begin(), s.end(), t[i]) == t[i] ) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}



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

int GCD(int a, int b){
	return (b == 0) ? a:GCD(b, a%b);
}
int LCM(int a, int b){
	return a/GCD(a, b)*b;
}

int main(){
	int a, b;
	while(cin >> a >> b){
		if(a < b)
			swap(a, b);
		cout << GCD(a, b) << " " << LCM(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n;
    cin >> n;

    int ma = 0, mb;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a > ma) {
            ma = a;
            mb = b;
        }
    }

    cout << ma + mb << endl;

    return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int cnt = 0;
  REP(i, N) {
    if (S[i] == 'o') cnt++;
  }
  int sub = 15 - N;
  if (cnt + sub >= 8) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256