akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi a;
ll tb[200001];
map<ll,ll> mp;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n; a.resize(n);
    rep(i,n)cin>>a[i];
    rep(i,200001)tb[i]=0;
    rep(i,n)tb[a[i]]++;
    ll ans = 0,tmp = 0;
    rep(i,200001){
        if(tb[i]>=2){
            tmp += tb[i]*(tb[i]-1)/2;
        }
    }
    rep(i,n){
        ans = tmp;
        if(tb[a[i]]>=2){
            ans = tmp - tb[a[i]]*(tb[a[i]]-1)/2;
            ans += (tb[a[i]]-1)*(tb[a[i]]-2)/2;
        }
        print(ans);
    }
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mo = 998244353;
const int N = 105;
string init;
int n;
map<string, int> f;

ll fet(string a) {
	// cout << a << endl;
	if (a.size() == 0) return 1;
	if (a.size() == 1) return 1 + a[0] - '0';
	if (f.count(a)) return f[a];
	ll ret = 0;
	ret = (1 + a[0] - '0') * fet(string(a.begin() + 1, a.end()));
	for(int p = 1; p * 2 <= a.length(); p++) {
		string nx = string(p, '1');
		for(int i = p - 1; i < a.length(); i += p) {
			for(int j = i - p + 1, cs = 0; j <= i; j++, cs++) {
				nx[cs] = ((nx[cs] - '0') & (a[j] - '0')) + '0';
			}
			if (i > p - 1)
				ret = (ret + fet(nx) * fet(string(a.begin() + i + 1, a.end()))) % mo;;
		}
	}
	return f[a] = ret % mo;
}

int main() {
	cin >> init;
	cout << fet(init) << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    int a, b, c, d;
    int n;
    cin >> n;
    a = n/1000;
    b = (n/100)%10;
    c = (n/10)%10;
    d = n%10;
    if(a+b+c+d == 7){cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;return 0;}
    if(a+b+c-d == 7){cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;return 0;}
    if(a+b-c+d == 7){cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;return 0;}
    if(a+b-c-d == 7){cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;return 0;}
    if(a-b+c+d == 7){cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;return 0;}
    if(a-b+c-d == 7){cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;return 0;}
    if(a-b-c+d == 7){cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;return 0;}
    if(a-b-c-d == 7){cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;return 0;}
}

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

const int mxN = 1e2 + 2, mxW = 1e5 + 4;
long long n, w, weights[mxN], values[mxN], dp[mxW];

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

    for (int i = 0; i < n; i++)
    {
        for (int j = w; j >= 0; j--)
        {
            if (j - weights[i] >= 0)
                dp[j] = max(dp[j], values[i] + dp[j - weights[i]]);
        }
    }

    long long ret = 0;
    for (int i = 0; i <= w; i++)
        ret = max(ret, dp[i]);
    cout << ret << endl;
}

Measured memory_bytes: 4412
N=int(input())
A=list(map(int,input().split()))
f=1
e=0
for i in range(N):
  if A[i]%2==0:
    if A[i]%3==0 or A[i]%5==0:
      e=e+1
    else:
      f=0
if f!=0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll n;
    cin >> n;
    vector<ll> a(n);

    ll p = 0;
    for(ll i = 0; i < n; i++) cin >> a[i];
    for(ll i = 0; i < n; i++){
        p += a[i];
        p += mod;
        p %= mod;
    }
    ll ans = 0;
    for(ll i = 0; i < n-1; i++){
        p -= a[i];
        p += mod;
        p %= mod;
        ans += (a[i]*p)%mod;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

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

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

    //good luck kittu!
    int n, k; cin>>k>>n;
    vector<int> a(2*n);
    for(int i = 0; i<n; i++){
        cin>>a[i];
        a[n+i] = k + a[i];
    }
    int ans = a[n-1]-a[0];
    for(int i = 0; i<=n; i++){
        ans = min(ans, a[n-1+i]-a[i]);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define a109 1000000009
#define mod 1000000007
#define pb push_back
using namespace std;

int n ,m,flag1;
int dp[3000][3000];
char c;


int main(){

	// freopen("a.gir","r",stdin);
 //    freopen("a.cik","w",stdout);

  	cin>>n>>m;
  	dp[1][1]=1;
  	for(int i=1;i<=n;i++){
  		for(int j=1;j<=m;j++){
  			cin>>c;
  			if(c!='#'){
  				dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%mod;
  				
  			}

  		}
  	}
  	printf("%d\n",dp[n][m] );

}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

int powmd(int a, int b) {
	if (b == 1)	return a;
	if (b == 0)	return 1;

	int half = powmd(a, b / 2);
	int ans = half * half;
	ans %= mod;
	if (b & 1) {
		ans *= a;
	}
	ans %= mod;
	return ans;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

int dp[10004][105][2];

int solve(string& k, int& d, int pos, int rem, int tight) {

	if (dp[pos][rem][tight] != -1)	return dp[pos][rem][tight];

	int up = (tight) ? (k[pos] - '0') : 9;
	int ans = 0;

	if (pos == k.length() - 1) {
		for (int i = 0; i <= up; i++) {
			if (rem == i % d)	ans++;
		}
		return dp[pos][rem][tight] = ans;
	}

	for (int i = 0; i <= up; i++) {
		ans += solve(k, d, pos + 1, (d + rem - (i % d)) % d, (tight and (i == (k[pos] - '0'))));
		ans %= mod;
	}
	return dp[pos][rem][tight] = ans;
}

int32_t main() {

	fastIO();

	string k;
	cin >> k;
	int d;
	cin >> d;
	memset(dp, -1, sizeof(dp));

	cout << (solve(k, d, 0, 0, 1) - 1 + mod) % mod << endl;

	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Measured memory_bytes: 20964
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define pb push_back
using ll = long long;
const ll M = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> is;
ll power(ll x,ll y){
    if(y==0)
    return 1;
    ll res=power(x,y/2);
    res=(res*res)%M;
    if(y&(ll)1)
    res=(res*x)%M;
    return res;
}
void solve(){
    int n,m;
    cin>>n>>m;
    string s="";
    for(int i=0;i<n;i++)
    s.pb('*');
    int a,b,f=1;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        if(s[a-1]!='*'&&s[a-1]!=(char)(b+48))
        {
            f=0;
        }
        s[a-1]=(char)(b+48);
    }
    if(n==1&&s[0]=='*')
    {
        cout<<0<<endl;
        return;
    }
    if(s[0]=='*')
    s[0]='1';
    for(int i=1;i<n;i++)
    {
        if(s[i]=='*')
        s[i]='0';
    }
    if((n!=1&&s[0]=='0')||f==0){
    cout<<-1<<endl;return;}
    cout<<s<<endl;
}
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e3 + 3;

int dp[MAXN];

int s;
int f(int cur) {
  if (cur <= 0)
    return cur == 0;
  int &ret = dp[cur];
  if (~ret)
    return ret;

  ret = 0;
  for (int i = 3; i <= cur; ++i) {
    ret += f(cur - i);
    ret %= MOD;
  }
  return ret;
}

// #define MULTIPLE_TEST_CASES
void solve() {
  memset(dp, -1, sizeof dp);
  cin >> s;
  cout << f(s) << endl;
}

signed main() {
  // freopen(".in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  for(int i = 0; i < 101; i++) {
    C -= B;
    if(C <= 0) {
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if(A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

double sq (double x) {return (x * x);}

int main(void)
{
	double x1, x2, x3, y1, y2, y3;
	int num;

	cin >> num;
	for (int i = 0; i < num; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
                //double a = sqrt(SQ(x2 - x1) + SQ(y2 - y1));
                //double b = sqrt(SQ(x3 - x2) + SQ(y3 - y2));
                //double c = sqrt(SQ(x1 - x3) + SQ(y1 - y3));
                double a = hypot(x2 - x1, y2 -y1);
                double b = hypot(x3 - x2, y3 -y2);
                double c = hypot(x1 - x3, y1 -y3);
                double r = (a * b * c) / sqrt( ( a + b + c ) * ( -1 * a + b + c) * ( a - b + c ) * ( a + b - c ) );


                double xp = ((sq(x1) + sq(y1)) * (y2 - y3) + (sq(x2) + sq(y2)) * (y3 - y1) + (sq(x3) + sq(y3)) * (y1 - y2)) / (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2;
                double yp = ((sq(x1) + sq(y1)) * (x2 - x3) + (sq(x2) + sq(y2)) * (x3 - x1) + (sq(x3) + sq(y3)) * (x1 - x2)) / (y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2)) / 2;

                printf("%.3f %.3f %.3f\n", xp, yp, r);
	}

	return 0;
}

Measured memory_bytes: 1256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 2500;
const int K = 19;
int n, q;
int mod = 998244353;
int a[N][N], f[N], invf[N], used[N];
vector < pair < int, int > > v;
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    if (k < 0) return 0;
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++) cin >> a[i][j];
    }
    int r = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (a[i][j] != 0 && !used[j]){
                used[j] = 1;
                for (int l = 1; l <= m; l++){
                    if (l != j && a[i][l] == 1){
                        for (int k = 1; k <= n; k++){
                            a[k][l] ^= a[k][j];
                        }
                    }
                }
                r++;
                break;
            }
        }
    }
    cout << (binpow(2, n + m - 1) - binpow(2, n + m - 1 - r) + mod) % mod;
}


Measured memory_bytes: 4992
def day(Y, m, d, Gregorian=True):
    from math import floor

    # ツェラーの公式
    if m <= 2:
        Y -= 1
        m += 12
    y = Y%100
    c = Y//100
    g = 5*c+floor(c/4) if Gregorian else 5-c
    return (d + floor(26*(m+1)/10) + y + floor(y/4) +  g) %7 # 0->土曜, 6->金曜

day_en = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    print(day_en[day(2004, m, d)])



Measured memory_bytes: 5664
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,temp,sum=0,r;
  cin>>n;
  temp = n;
  while(temp!=0)
  {
    r = temp%10;
    sum = sum*10 + r;
    temp=temp/10;
  }
  
  if(sum==n)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
}

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

struct BipartiteMatching {
	int V;
	vector<vector<bool> > G;
	vector<int> match;
	vector<bool> used;

	BipartiteMatching(int v) {
		V = v;
		G = vector<vector<bool> >(v, vector<bool>(v));
		match = vector<int>(v);
		used = vector<bool>(v);
	}

	void add_edge(int v, int u) {
		G[v][u] = G[u][v] = true;
	}

	bool dfs(int v) {
		used[v] = true;
		for(int i = 0; i < V; i++) {
			if(!G[v][i]) continue;
			int u = i, w = match[u];
			if(w < 0 || (!used[w] && dfs(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}

	int calc() {
		int res = 0;
		fill(match.begin(), match.end(), -1);
		for(int v = 0; v < V; v++) {
			if(match[v] < 0) {
				fill(used.begin(), used.end(), false);
				if(dfs(v)) {
					res++;
				}
			}
		}
		return res;
	}
};


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

	int N;
	while(cin >> N, N) {
		int M;
		cin >> M;
		map<int, int> id;
		for(int i = 0; i < M; i++) {
			int a;
			cin >> a;
			id[a] = -1;
		}
		int cnt = 0;
		for(auto v : id) {
			id[v.first] = cnt++;
		}

		BipartiteMatching bm(cnt + N);
		for(int i = 0; i < N; i++) {
			cin >> M;
			for(int j = 0; j < M; j++) {
				int a;
				cin >> a;
				if(id.count(a) == 0) continue;
				bm.add_edge(id[a], cnt + i);
			}
		}

		cout << bm.calc() << endl;
	}

}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 50600
#define MOD 999983
#define MAXV 1010
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define PAD 300
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pi;
typedef vector<vector<long long> > mat;

int main () {
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	printf("%lld\n",max(0LL,(n-1LL)*b + a - (n-1LL) * a - b + 1LL));
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")
from collections import Counter


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


def solve(N: int, A: "List[int]"):
    counter = Counter()
    flag = True
    for a in A:
        counter[a] += 1
        if counter[a] > 1:
            flag = False
            break
    if flag:
        yes()
    else:
        no()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


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

int main() {
  int a, b, c, s;
  cin >> a >> b >> c;
  if(a == b && b==c){
  s = 1;}
  else if(a != b && b != c && c!= a){
  s = 3;}
  else{
  s = 2;}
  cout << s << endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main()
{
	int n,r=0,count=0;
	char ch[200010];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>ch[i];
		if(ch[i]=='W')
			count++;
	}
	for(int i=n-count;i<n;i++)
		if(ch[i]=='R')
			r++;
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
# define ld long double
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int ma=1e5+5;
int h,w;
char arr[25][25];
int bfs(int p,int q)
{
  vector<vector<int> >dis(h);
  for(int i=0;i<h;i++)
  {
    dis[i].resize(w);
    for(int j=0;j<w;j++)
    dis[i][j]=0;
  }

  queue< pair<int,int> >Q;
  Q.push({p,q});
  dis[p][q]=1;
  int mx=-1;

  while(!Q.empty())
  {
    pair<int,int>pt=Q.front();
    //cout<<pt.fi<<" "<<pt.se<<endl;
    Q.pop();

      if(pt.fi-1>=0 && dis[pt.fi-1][pt.se]==0 && arr[pt.fi-1][pt.se]=='.' )
      {
        dis[pt.fi-1][pt.se]=dis[pt.fi][pt.se]+1;
        Q.push({pt.fi-1,pt.se});
        mx=max(mx,dis[pt.fi-1][pt.se]);
      }

      if(pt.fi+1<h && dis[pt.fi+1][pt.se]==0 && arr[pt.fi+1][pt.se]=='.' )
      {
        dis[pt.fi+1][pt.se]=dis[pt.fi][pt.se]+1;
        Q.push(mp(pt.fi+1,pt.se));
        mx=max(mx,dis[pt.fi+1][pt.se]);
      }

      if( pt.se-1>=0 && dis[pt.fi][pt.se-1]==0 && arr[pt.fi][pt.se-1]=='.')
      {
        dis[pt.fi][pt.se-1]=dis[pt.fi][pt.se]+1;
        Q.push({pt.fi,pt.se-1});
        mx=max(mx,dis[pt.fi][pt.se-1]);
      }

      if(pt.se+1<w && dis[pt.fi][pt.se+1]==0 && arr[pt.fi][pt.se+1]=='.' )
      {
        dis[pt.fi][pt.se+1]=dis[pt.fi][pt.se]+1;
        Q.push({pt.fi,pt.se+1});
        mx=max(mx,dis[pt.fi][pt.se+1]);
      }
  }
return mx-1;
}
int main()
{
  cin>>h>>w;
  int mx=0;

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    cin>>arr[i][j];

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    {
      if(arr[i][j]=='.')
        mx=max(mx,bfs(i,j));
    }
    cout<<mx<<endl;
  return 0;
}


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

int main(){
    string S, T;
    cin >> S >> T;

    if(S.at(0) == T.at(2) && S.at(1) == T.at(1) && S.at(2) == T.at(0)){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1};

ll choose2(ll n)
{
    return n * (n - 1) / 2;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    vector<int> cnt(n);
    rep(i, n) cnt[a[i]]++;
    ll tot = 0;
    rep(i, n)
    {
        tot += choose2(cnt[i]);
    }
    rep(i, n)
    {
        ll ans = tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]] - 1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N;

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

string s = "ENWS";

int main()
{
    while (cin >> N)
    {
        if (N == 0)
            return 0;
        vector<int> x(N), y(N);
        for (int i = 0; i < N; i++)
            cin >> x[i] >> y[i];
        int X = 10, Y = 10, M;
        cin >> M;
        for (int i = 0; i < M; i++)
        {
            char c;
            int a, dic;
            cin >> c >> a;
            for (int j = 0; j < 4; j++)
            {
                if (s[j] == c)
                    dic = j;
            }
            for (int j = 0; j < a; j++)
            {
                X += dx[dic], Y += dy[dic];
                for (int k = 0; k < N; k++)
                {
                    if (X == x[k] && Y == y[k])
                        x[k] = -1, y[k] = -1;
                }
            }
        }
        bool f = true;
        for (int j = 0; j < N; j++)
        {
            if (x[j] != -1 && y[j] != -1)
                f = false;
        }
        cout << (f ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int main(){
  int r,d,x;
  cin >> r >> d >> x;
  rep(i,10){
    x = r*x -d;
    cout << x << endl;
  }
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int color[100000];
vector<int> to[100000];


bool DFS(int x, int C){
  color[x] = C;
  for(int a: to[x]){
    if(color[a]==C) return false;
    if(color[a]==-1 && !DFS(a, 1-C)) return false;
  }
  return true;
}


int main(){
  int N, M; cin >> N >> M;
  rep(i, N)color[i]=-1;
  rep(i, M){
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b); to[b].push_back(a);
  }
  if(DFS(0,0)){
    int B=0, W=0;
    rep(i, N){
      if(color[i]==0) B++;
      else W++;
    }
    cout << (ll) B*W - M << endl; return 0;
  }
  cout << (ll) N*(N-1)/2 - M << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#define INF 100000
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, T;
	cin >> n >> T;
	int c, t;
	int ans = INF;
	for(int i = 0; i < n; i++)
	{
		cin >> c >> t;
		if(t <= T)
		{
			if(c < ans)
				ans = c;
		}
	}
	if(ans == INF)
		cout << "TLE" << endl;
	else
		cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

bool rect(int a, int b, int c) {
	return pow(c,2)==pow(b,2)+pow(a,2);
}

int main() {
	int fs, ss, di, rec=0, loz=0;
	while (scanf("%d,%d,%d",&fs,&ss,&di)!=EOF) {
		if (fs!=ss&&rect(fs,ss,di)) rec++;
		else if (!rect(fs,ss,di)&&fs==ss) loz++;
	}
	cout << rec << endl;
	cout << loz << endl;
}

Measured memory_bytes: 0
#include<stdio.h>

int main()
{
  int i,j,k;
  int dp[4001][4];
  for(i=1;i<5;i++)
    for(j=0;j<4001;j++)
      dp[j][i-1] = i==1&&j<=1000?1:0;

  for(i=2;i<=4;i++)
    for(j=0;j<=4000;j++)
      for(k=0;k<=j && k<=1000;k++)
	dp[j][i-1] += dp[j-k][i-2];

  int n;
  while(scanf("%d",&n) != EOF)
    printf("%d\n",dp[n][3]);
    
  return 0;
}

Measured memory_bytes: 664
#include<bits/stdc++.h>
using namespace std;
const long long INF=1LL<<62;
inline void read(int &x){
    x=0;
    char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
}
int main(){
    int a,b,c,d;
    read(a);
    d=a%60;
    c=a/60;
    b=c/60;
    c-=b*60;
    cout<<b<<":"<<c<<":"<<d<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;


// aのn乗mod(p) の繰り返し2乗法
int modPow(long long a, long long n, long long p) {
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}
 
ll comb(ll n, ll p) {
	if (p * 2 > n) p = n - p;
	if (p > n - p) p = n - p;
	ll a = 1, b = 1;
	for(ll i=1;i< p+1 ;++i) {
		a = (a * (n - i + 1)) % int((1e9 + 7));
		b = (b * i) % int((1e9 + 7));
	}
	return a * (modPow(b, (1e9 + 7) - 2, (1e9 + 7))) % int((1e9 + 7));
}

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

  ll modbase = modPow(2, n, 1e9 + 7) -1;
  ll moda = comb(n,a);
  ll modb = comb(n,b);
  ll ans = modbase - moda - modb;

  while(!(ans >= 0)) ans += 1e9 + 7;

  dunk(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand((unsigned)time(NULL));
  ll H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  for(int i = 0; i < H; i++){
    cin >> S.at(i);
  }
  ll ans = 0;
  for(int bit = 0; bit < (1<<(H+W)); bit++){
    ll counter = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if( (bit >> i) & 1 ) continue;
        if( (bit >> (H+j)) & 1) continue;
        if(S.at(i).at(j) == '#') counter++;
      }
    }
    if(counter == K) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
#define FAIL { cout << "NO\n"; return 0; }

int main() {
    string s1, s2 = "AKIHABARA";
    cin >> s1;

    int i = 0, j = 0;
    for (;i < s1.size() && j < s2.size(); i++) {
        if (s1[i] != s2[j]) {
            if (s2[j] != 'A') FAIL;
            i--;
        }
        j++;
    }
    while (j < s2.size() && s2[j] == 'A') j++;
    if (i != s1.size() || j != s2.size()) FAIL;
    cout << "YES\n";
}

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



using namespace std;

long pow(long x, long y, long mod) {
    long ret = 1;
    long tmp = x;
    while (y) {
        if (y % 2) ret = ret * tmp % mod;
        y /= 2;
        tmp = tmp * tmp % mod;
    }
    return ret;
}

long inverse(long v, long mod) {
    return pow(v, mod - 2, mod);
}

long factorial(long x, long mod) {
    long ret = 1;
    for (long i = 1; i <= x; i++) {
        ret = ret * i % mod;
    }
    return ret;
}

long combination(long x, long y, long mod) {
    long ret = factorial(x, mod);
    ret = ret * inverse(factorial(y, mod), mod) % mod;
    ret = ret * inverse(factorial(x - y, mod), mod) % mod;
    return ret;
}



int main() {
    long r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    long MOD = 1000000007;
    auto f = [&](long x, long y) { return combination(x + y, y, MOD); };
    cout << (f(r2 + 1, c2 + 1) - f(r1, c2 + 1) - f(r2 + 1, c1) + f(r1, c1) + MOD) % MOD << endl;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()
    H = LIST()

    l = [1 for _ in range(N)]
    for _ in range(M):
        A, B = MAP()
        if H[A-1] < H[B-1]:
            l[A-1] = 0
        elif H[A-1] > H[B-1]:
            l[B-1] = 0
        else:
            l[A-1] = 0
            l[B-1] = 0

    print(sum(l))


if __name__ == '__main__':
    main()

Measured memory_bytes: 21156
#include <stdio.h>

char str[55];
int N, K;

int main() {
  scanf("%d %d",&N,&K);
  scanf("%s", str);
  if(str[K - 1] == 'A'){
    str[K - 1] = 'a';
  }
  else if(str[K - 1] == 'B'){
    str[K - 1] = 'b';
  }
  else {
    str[K - 1] = 'c';
  }
  printf("%s", str);


  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }

  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }

  string word;
  int ans = -100, tmp;
  for (int i = 0; i < N; i++) {
    word = s.at(i);
    tmp = 0;
    for (int i = 0; i < N; i++) {
      if (word == s.at(i)) tmp++;
    }
    for (int i = 0; i < M; i++) {
      if (word == t.at(i)) tmp--;
    }
    if (ans < tmp) {
      ans = tmp;
    }
  }

  if (ans <= 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N+1,0); FOR(i,1,N+1) cin >> A[i];
    A.push_back(0);

    ll sum = 0;
    REP(i,N+1) {
        sum += abs(A[i+1] - A[i]);
    }

    FOR(i,1,N+1) {
        ll ans = sum;
        ans -= abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]);
        ans += abs(A[i + 1] - A[i - 1]);

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

Measured memory_bytes: 1656
import java.io.PrintWriter

@JvmField val _writer = PrintWriter(System.out, false)
fun main(args: Array<String>) { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
    var n = readLine()!!.toInt()
    val ans = mutableSetOf<String>()
    repeat(n) {
        ans.add(readLine()!!)
    }
    println(ans.size)
}


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

long long int gcd(long long int a,long long int b);
long long int lcm(long long int a,long long int b);

long long int gcd(long long int a,long long int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
long long int lcm(long long int a,long long int b){
  return a*b/gcd(a,b);
}

int main()
{
  long long int a1,a2,a3,m1,m2,m3;
  long long int x,y,z;
  long long int count;

  while (cin>>a1>>m1>>a2>>m2>>a3>>m3, a1||a2||a3||m1||m2||m3) {
    x = (1 * a1) % m1;
    y = (1 * a2) % m2;
    z = (1 * a3) % m3;
    count = 1;
    while (x!=1) {
      x = (x * a1) % m1;
      count ++;
    }
    x = count;
    count = 1;
    while (y!=1) {
      y = (y * a2) % m2;
      count ++;
    }
    y = count;
    count = 1;
    while (z!=1) {
      z = (z * a3) % m3;
      count ++;
    }
    z = count;
    cout<<lcm( x, lcm(y, z) )<<endl;
  }
  return 0;
}

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

int main() {
    uint64_t N, M;
    std::cin >> N >> M;

    std::unordered_set<uint64_t> a; 
    uint64_t buf;
    for (size_t i = 0; i < M; ++i) {
        std::cin >> buf;
        a.insert(buf);
    }

    uint64_t dp[N + 1];
    dp[0] = 1;
    if (a.count(1) == 0) {
        dp[1] = 1;
    } else {
        dp[1] = 0;
    }

    for (size_t i = 1; i < N; ++i) {
        if (a.count(i + 1) != 0) {
            dp[i+1] = 0;
        } else if (a.count(i) == 0 && a.count(i-1) == 0) {
            dp[i+1] = dp[i] + dp[i-1];
        } else if (a.count(i) != 0 && a.count(i-1) == 0) {
            dp[i+1] = dp[i-1];
        } else if (a.count(i) == 0 && a.count(i-1) != 0) {
            dp[i+1] = dp[i];
        } else {
            dp[i+1] = 0;
        }

        dp[i+1] %= 1000000007;
    }

    std::printf("%lu\n", dp[N]);

    return 0;
}


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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

ll n, x, a[3000], m[3000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> x;
  for (int i = 0; i < n; i++)
    cin >> a[i], m[i] = a[i];
  ll r = 1LL << 60;
  for (int i = 0; i < n; i++) {
    ll h = x * i;
    for (int j = 0; j < n; j++)
      m[j] = min(m[j], a[(j - i + n) % n]), h += m[j];
    r = min(r, h);
  }
  cout << r << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

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

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

const int WHITE = 0, BLACK = 1;
int n;
vector<int> G[100010];
int dp[100010][2];

void dfs(int from, int par) {
    if(dp[from][BLACK] != -1) return;
    bool havechild = false;
    int reca = 1, recb = 1;
    for(auto to : G[from]) {
        if(to == par) continue;
        havechild = true;
        dfs(to, from);
        int a = dp[to][WHITE], b = madd(a, dp[to][BLACK]);
        reca = mmul(reca, a);
        recb = mmul(recb, b);
    }
    if(!havechild) dp[from][WHITE] = dp[from][BLACK] = 1;
    else {
        dp[from][BLACK] = reca;
        dp[from][WHITE] = recb;
    }
}

signed main() {
    memset(dp, -1, sizeof(dp));
    cin >> n;
    rep(i,0,n-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1);
    int ans = madd(dp[0][0], dp[0][1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define pb push_back 
#define pob pop_back
#define mp make_pair

void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans =1e9;
	ans = min((a+b),min(a+c,min(b+a,min(b+c,min(c+a,c+b)))));
	cout<<ans;
}

int main(){

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1; 
    while(t--){
      solve();
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, num = 0;
  cin >> A >> B;
  
  for(int i= A; i <= B; i++){
    int s1, s2, s4, s5;
    
    s1 = i % 10;
    s2 = (i % 100) / 10;
    s4 = (i % 10000) / 1000;
    s5 = i / 10000;
    
    if(s1 == s5 && s2 == s4)
      num++;
  }
  
  cout << num << endl;
    
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	items := make([]Item, n)
	var a, b int
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b)
		items[i] = Item{i, a, b}
	}

	sort.Sort(Items(items))

	sa, sb := 0, 0
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			sa += items[i].a
		} else {
			sb += items[i].b
		}
	}

	fmt.Println(sa - sb)
}

// Item .
type Item struct {
	i, a, b int
}

// Items .
type Items []Item

func (a Items) Len() int      { return len(a) }
func (a Items) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Items) Less(i, j int) bool {
	return a[i].a+a[i].b > a[j].a+a[j].b
}


Measured memory_bytes: 5760
fn main() {
    let v = read_vec::<u32>();
    let w = v[0];
    let h = v[1];
    let n = v[2];
    let z = read_vec2::<u32>(n);

    let mut xmin = 0;
    let mut ymin = 0;
    let mut xmax = w;
    let mut ymax = h;

    for e in z.iter() {
        let x = e[0];
        let y = e[1];
        let a = e[2];
        match a {
            1 => xmin = std::cmp::max(xmin, x),
            2 => xmax = std::cmp::min(xmax, x),
            3 => ymin = std::cmp::max(ymin, y),
            4 => ymax = std::cmp::min(ymax, y),
            _ => break,
        }
    }
    if xmax > xmin && ymax > ymin {
        println!("{}", (xmax-xmin)*(ymax-ymin));
    } else {
        println!("0");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


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


int main() {
    int K, S;
    cin >> K >> S;
    ll ans = 0;
    rep(x, K + 1) {
        rep(y, K + 1) {
            int z = S - x - y;
            if (z >= 0 && z <= K && x + y + z == S) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
maxV = 80*(80+80)

H, W = map(int, input().split())
Ass = [tuple(map(int, input().split())) for _ in range(H)]
Bss = [tuple(map(int, input().split())) for _ in range(H)]

dp = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        A, B = Ass[i][j], Bss[i][j]
        if A > B:
            A, B = B, A
        if i == 0 and j == 0:
            dp[i][j] = 1<<(maxV+B-A) | 1<<(maxV-B+A)
        if i > 0:
            dp[i][j] |= dp[i-1][j]<<(B-A) | dp[i-1][j]>>(B-A)
        if j > 0:
            dp[i][j] |= dp[i][j-1]<<(B-A) | dp[i][j-1]>>(B-A)

bitset = dp[-1][-1]
mask = 1<<(2*maxV)
ans = maxV
for i in range(-maxV, maxV+1):
    if bitset & mask:
        ans = min(ans, abs(i))
    mask >>= 1

print(ans)


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

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

    vector<int> A(200);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    int alice = 0, bob = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0)
            alice += A.at(i);
        else
            bob += A.at(i);
    }
    cout << (alice - bob) << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  for (int i=0; i<N; ++i) {
    int h;
    cin >> h;
    if (h >= K) ++ans;
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;


long long n;
long long a[100000];
vector<long long> hai;
int main()
{
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n-1)
	{
		if(a[i]==a[i+1])
		{
			hai.push_back(a[i]);
			i++;
		}
	}
	if(hai.size()>1)
	{
		cout<<hai[hai.size()-1]*hai[hai.size()-2]<<endl;
	}
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 1660
class Solution:

    def solve(self, N: str) -> int:

        L = len(N)
        D = []
        for l in range(L-1, -1, -1):
            D.append(int(N[l]))

        D.append(0)

        ans = 0
        for l in range(L+1):

            # carry over
            if D[l] == 10:
                D[l+1] += 1
                D[l] = 0

            if D[l] < 5:
                ans += D[l]
            elif D[l] == 5:
                if D[l+1] >= 5:
                    D[l+1] += 1
                ans += 5
            else:
                ans += 10-D[l]
                D[l+1] += 1

#            print(D[l], ans)

        return ans


if __name__ == '__main__':

    # standard input
    N = input()

    # solve
    solution = Solution()
    print(solution.solve(N))


Measured memory_bytes: 15672
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int C[9];
int INV[200];
typedef long long ll;
int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    
    ll a = N/(A+B);
    ll b = N - a *(A+B);
    
    cout << a * A + min(b, A);
    return 0;
}


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

int main() {
    vector<int> n(3);
    cin>>n.at(0)>>n.at(1)>>n.at(2);
    sort(n.begin(),n.end());
    
    cout<<n.at(0)+n.at(1)<<endl;
    
}

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

int counter[1005];

void setcount(int n){
  int i=2;
  while(n>=i){
    if(n%i==0) {
      counter[i]++;
      n/=i;
    }else i++;
  }
}

int main(){
  int N;
  long long sum=1;
  long long figure=pow(10,9)+7;
  cin >> N;
  for(int i=0;i<=N;i++) counter[i]=0;

  for(int i=2;i<=N;i++) setcount(i);
  for(int i=1;i<=N;i++){
    sum *=(counter[i]+1);
    if(sum>figure) sum%=figure;
  }
  cout << sum << endl;;
  return 0;
}


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

int main(void) {
    int X;
    int i;
    int j;
    int tmp;
    int ans=0;
    
    scanf("%d",&X);

    for (i=0; i<=(int)sqrt(X); i++) {
        for (j=2; j<11; j++) {
            tmp=(int)pow(i,j);
            if((ans<tmp) && (X>=tmp)) {
                ans=tmp;
            }
        }
    }
    printf("%d",ans);
    
    return 0;
    
}

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

//#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "YES" : "NO")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 3e3 + 10;
const int SIZ = 3e3 + 10;
const int mod = 998244353;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "2";

int n, s;
int a[siz];
int f[siz][SIZ];

int dp(int pos, int sum) {
    if (pos == n + 1) {
        return (sum == s);
    }

    int &res = f[pos][sum];
    if (res != -1) {
        return res;
    }

    res = dp(pos + 1, sum); /// only put to N

    (res += dp(pos + 1, sum)) %= mod; /// do not put

    if (sum + a[pos] <= s)
        (res += dp(pos + 1, sum + a[pos])) %= mod; /// put to both N and T

    return res;
}

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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

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

    memset(f, -1, sizeof(f));

    cout << dp(1, 0) << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 39144
#include <iostream>

using namespace std;

#define MAX 21
 
string str[MAX];
int n,m,cnt,dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
 
void dfs(int x,int y){
    str[x][y] = '#';
 
    for(int i = 0 ; i < 4 ; i++){
	int nx = x + dx[i] , ny = y + dy[i];
	if(0 <= nx && nx < m && 0 <= ny && ny < n){
	    if(str[nx][ny] == '.'){
		cnt++;
		dfs(nx,ny);
	    }
	}
    }
}
 
int main(){
    while(cin >> n >> m , n + m){
	for(int i = 0 ; i < m ; i++){
	    cin >> str[i];
	}
     
	int x,y;
	for(int i = 0 ; i < n ; i++){
	    for(int j = 0 ; j < m ; j++){
		if(str[j][i] == '@'){
		    x = j;
		    y = i;
		    break;
		}
	    }
	}
	cnt = 1;
	dfs(x,y);
	cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3128