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

int main()
{
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if (c % 2 == 0)
  {
    cout << "Even";
  }
  else
  {
    cout << "Odd";
  }
}


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

int main(){
  int n;
  string s;
  cin >>n >>s;
  int ans = 0;
  rep(i,n-2){
    if(s[i] == 'A' and s[i+1]== 'B' and s[i+2] == 'C') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

#define INF (1<<31-1)
#define ll long long

int digitsum(int n){
	int s = 0;
	while (n > 0){
		s += n % 10;
		n /= 10;
	}
	return s;
}

int main(){

	ll N;
	ll result;

	cin >> N;

	if (N % digitsum(N)==0)	cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define piii pair<int, pii>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

int h, w, k;
int sx, sy, gx, gy;
vector<string> c;

void init()
{
	cin >> h >> w >> k;
	cin >> sy >> sx >> gy >> gx;
	rep(i, h)
	{
		string s;
		cin >> s;
		c.push_back(s);
	}

	sx--;
	sy--;
	gx--;
	gy--;
}

void solve()
{
	queue<piii> que;
	que.push(piii(0, pii(sx, sy)));

	int ans = -1;

	while (!que.empty())
	{
		piii top = que.front();
		que.pop();

		int cost = top.first;
		int x = top.second.first;
		int y = top.second.second;

		if (c[y][x] == 'o')
		{
			continue;
		}
		c[y][x] = 'o';

		// cout << "cha " << cost << " " << x << " " << y << endl;
		// rep(i, h) cout << c[i] << endl;

		if (x == gx && y == gy)
		{
			ans = cost;
			break;
		}

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

		rep(i, 4)
		{
			reps(dist, 1, k + 1)
			{
				int nx = x + dist * dx[i];
				int ny = y + dist * dy[i];

				if (nx < 0 || nx >= w | ny < 0 || ny >= h)
				{
					break;
				}

				if (c[ny][nx] == '@' || c[ny][nx] == 'o')
				{
					break;
				}

				if (c[ny][nx] != '.')
				{
					continue;
				}

				c[ny][nx] = 'x';
				que.push(piii(cost + 1, pii(nx, ny)));
			}
		}
	}

	cout << ans << endl;
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	string s;
	ll k;
	cin >> s >> k;
	if (k <= s.length()){
		for (int i = 0; i < k; i++){
			if (s[i] != '1'){
				cout << s[i] << endl;
				return 0;
			}
		}
		cout << s[k-1] << endl;
	}else{
		for (int i = 0; i < s.length(); i++){
			if (s[i] != '1'){
				cout << s[i] << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val d = sc.nextInt()
    println(if (Math.min(b,d) - Math.max(a,c) > 0) Math.min(b,d) - Math.max(a,c) else 0)
}


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

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if(A1 + A2 + A3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
s = input()
if len(s) == 4:
    if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
        print('Yes')
    elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]:
        print('Yes')
    elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#define int long long

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

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    int ok = 0, ng = n;
    string f;

    cout << 0 << endl;
    cin >> f;
    if (f == "Vacant")
        return 0;
    int se = f == "Male" ? 0 : 1;

    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        string re;
        cout << mid << endl;
        cin >> re;
        if (re == "Vacant")
        {
            return 0;
        }
        int cur = re == "Male" ? 0 : 1;
        if ((mid - ok) % 2 == 0)
        {
            if (cur == se)
                ok = mid, se = cur;
            else
                ng = mid;
        }
        else
        {
            if (cur != se)
                ok = mid, se = cur;
            else
                ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 852
S=input()

for i in range(1, len(S)):
  s=S[0:len(S)-i]
  #print(s)
  if len(s)%2==1:
    continue
  #print('pre', s[0:int(len(s)/2)+1])
  #print('follow', s[int(len(s)/2):len(s)])
  if s[0:int(len(s)/2)]==s[int(len(s)/2):len(s)]:
    print(len(S)-i)
    break

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll gcd (ll a, ll b)
{
    return b == 0 ? a : gcd(b,a % b);
}
int main()
{
   int n, x; cin >> n; int b[n + 10];
   for(int i = 1; i <= n ; i++)
   {
       cin >> x;
       b[x] = i;
   }
   for(int i = 1; i <= n ;i++)
   {
       cout << b[i] << ' ';
   }

}


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

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
} 
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

inline int Pow(int a, int k) {
  int s = 1; 
  for(; k; k >>= 1) {
    k & 1 ? s = 1LL * s * a % MOD : 0;
    a = 1LL * a * a % MOD;
  }
  return s;
}

const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
}

void preprocess() {
}

void debug() {
  //  44gg
  if (true) {
  
  }
}



void solve() {
  preprocess();
  // 50gg
  int a, b;
  cin >> a >> b;
  int res = 0;
  b++;
  FOR(i, 0, 50) {
    int p = 1LL << (i + 1);
    int p2 = p / 2;
    //cerr << "p = " << p << endl;
    int L = (a / p) * p2;
    L += max(0LL, (a % p) - p2);
    int R = (b / p) * p2;
    R += max(0LL, (b % p) - p2);
    if ((R - L) % 2) {
      res |= p2;
    }
    //cerr << i << ' ' << p << ' ' << L << ' ' << R << ' ' << res << endl;
  }
  cout << res << endl;
  //debug();
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

void output() {

}

#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--) 
  {
    input();
    solve();
    output();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>//"M_PI"→円周率(小数点以下5桁)
#include<iomanip>//fixed<<setprecision(15)<<
#define LL long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define E "\n"
#define PI 3.141592653589793


int main(){
  string a;cin>>a;
  int cnt=count(a.begin(),a.end(),'1');
  cout<<cnt<<E;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(){

  int n,i;
  long long int a,b,ans=0,tmp;
  int x[100010];

  scanf("%d %lld %lld",&n,&a,&b);

  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
  }
  for(i=0;i<n-1;i++){
    tmp=(x[i+1]-x[i])*a;
    if(tmp>b){
      ans+=b;
    }else{
      ans+=tmp;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define N 1000123
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define pb emplace_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define oo 1000000123
#define mod 1000000007LL
#define M 10000123
 
using namespace std;

map<string, int> msi;
string s;
int n;
 
int main(){
    ios_base::sync_with_stdio(0);
    cin >> n;
    while(n--){
        cin >> s;
        msi[s]++;
    }
    cout << "AC x " << msi["AC"] << '\n';
    cout << "WA x " << msi["WA"] << '\n';
    cout << "TLE x " << msi["TLE"] << '\n';
    cout << "RE x " << msi["RE"] << '\n';
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>

using namespace std;

const long long MAXN = 1e5+10;
const long long MOD = 1e9+7;
long long cnt[MAXN];
long long PowMod(long long a,long long b,long long c)  //快速求 a^b % c ，要避免计算中间结果溢出
{
    long long result = 1;
    long long base = a%c;
    while(b)
    {
        if( b & 1)
            result = (result * base)%c;
        base = (base * base) % c;
        b >>= 1;
    }
    return result;
}

int main()
{
    long long N;
    cin >> N;
    for(long long i = 0 ; i < N ; i++)
    {
        long long t;
        cin >>t;
        cnt[t]++;
    }
    bool flag = true;
    long long temp = 0;
    for(long long i = 1 ; i < N ; i++)
    {
        if(cnt[i]!=2&&cnt[i]!=0)
        {
            flag = false;
        }
    }
    if(N%2==1&&cnt[0]!=1)
    {
        flag = false;
    }
    flag?cout<<PowMod(2,N/2,MOD)<<endl:cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

class Point {
public:
    int _x, _y;
    Point(int x, int y): _x(x), _y(y){}
    Point(const Point& a): _x(a._x), _y(a._y){}

    Point operator+(const Point& a){
        return Point(_x - a._x, _y - a._y);
    }
    Point operator-(const Point& a){
        return Point(_x - a._x, _y - a._y);
    }
    void operator=(const Point& a){
        _x = a._x;
        _y = a._y;
    }
    double dot(const Point& a){
        return (_x*a._x + _y*a._y);
    }
};

bool isParallel(Point x1, Point x2){
    return ( x1._x * x2._y - x1._y*x2._x == 0 );
}

typedef Point Vec;

int main(){
    int q;

    scanf("%d",&q);
    for(int i=0; i<q; ++i){
        int ax,ay,bx,by,cx,cy,dx,dy;
        scanf("%d %d %d %d %d %d %d %d",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
        Vec a(ax,ay), b(bx,by), c(cx,cy), d(dx,dy);
        Vec x1(a-b), x2(c-d);
        if( (int)x1.dot(x2) ==0 ){
            cout << 1 << endl;
        }
        else if(isParallel(x1,x2)){
            cout << 2 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3244
N, M = map(int, input().split())
H = list(map(int, input().split()))
graph = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a - 1].add(b - 1)
    graph[b - 1].add(a - 1)

good = [-1] * N
for i in range(N):
    if good[i] != -1:
        continue
    if not graph[i]:
        good[i] = 1
    elif all(H[nei] < H[i] for nei in graph[i]):
        good[i] = 1
        for nei in graph[i]:
            good[nei] = 0
    else:
        good[i] = 0

print(sum(good))

Measured memory_bytes: 46080
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 300 + 10;
int64 dp[N][N][N];

void add(int64& x, int64 y) {
  x = (x + y) % MOD;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    for (int j = 1; j <= i + 1 && j <= n; ++j) {
      for (int k = 1; k <= j; ++k) {
        if (i == 0) dp[i][j][k] = 1;
        add(dp[i + 1][j + 1][k], dp[i][j][k] * (n - j) % MOD);
        add(dp[i + 1][j][j], dp[i][j][k] * k % MOD);
        add(dp[i + 1][j][k], dp[i][j][k] * (j - k) % MOD);
      }
    }
  }
  printf("%lld\n", dp[m][n][n]);
  return 0;
}


Measured memory_bytes: 225536
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0
    cur = 0
    for i in range(n):
        cur += a[i]
        if i == n-1 or a[i] == 0:
            ans += cur//2
            cur = 0
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 49624
#include <stdio.h>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

char st[100];


int main()
{
    int n;scanf("%d",&n);
    scanf("%s",st);
    int ans=0;
    for (int i=0;i+2<n;++i)
    if (st[i]=='A' && st[i+1]=='B' && st[i+2]=='C')
        ans+=1;
    printf("%d\n",ans);


}


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

using namespace std;

int main() {
    string s, nuki;
    cin >> s;
    int n = 0;
    vector<int> xp;
    for (auto c:s) {
        if (c == 'x') xp.push_back(n);
        else {
            n++;
            nuki += c;
        }
    }
    size_t len = nuki.size();
    for (size_t i=0; i<len; i++) {
        if (nuki[i] != nuki[len-i-1]) {
            cout << -1 << '\n';
            return 0;
        }
    }
    if (xp.empty() || nuki.empty()) {
        cout << 0 << '\n';
        return 0;
    }
    int i = 0, j = xp.size() - 1;
    int cnt=0;
    while (i <= j) {
        while (xp[i] + xp[j] > n)
            j--;
        if (i <= j && xp[i] + xp[j] == n) {
            cnt += (i == j ? 1 : 2);
            j--;
        }
        i++;
    }
    cout << xp.size() - cnt << '\n';
    return 0;
}

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

int main(void)
{
  std::string str;
  std::cin >> str;

  int n = str.size() - 1;
  int64_t ans = 0;
  int64_t tmp;

  for (int i = 0; i < (1 << n); i++) {
    tmp = str[0] - '0';

    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        ans += tmp;
        tmp = str[j+1] - '0';
      }
      else {
        tmp = tmp*10 + (str[j+1]-'0');
      }
    }
    ans += tmp;
  }
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    long long int A[100000],B[100000];
    cin>>N;
    for(int i=0;i<N;i++)cin>>A[i]>>B[i];
    long long int ans=0;
    for(int i=N-1;0<=i;i--){
        if((A[i]+ans)%B[i]!=0)ans+=B[i]-((A[i]+ans)%B[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
for _ in range(10000):
    m,f,r = map(int,input().split())
    if (m==-1) and (f==-1) and (r==-1):
        break
    if (m==-1) or (f==-1):
        print('F')
        continue
    elif (m+f>=80):
        print('A')
        continue
    elif (m+f>=65):
        print('B')
        continue
    elif (m+f>=50):
        print('C')
        continue
    elif (m+f>=30):
        if (r>=50):
            print('C')
            continue
        else:
            print('D')
            continue
    else:
        print('F')
        continue


Measured memory_bytes: 5596
import sys
#やけくそ
def 解():
    iN,iM = [int(_) for _ in input().split()]
    aPM = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
    dC = {}
    def addCity(d,p,m,i):
        if p in d:
            d[p].append((m,i))
        else:
            d[p]=[(m,i)]

    iIndex = 1
    for p,m in aPM:
        addCity(dC,p,m,iIndex)
        iIndex += 1
    oAns = []

    for iCity in dC.keys():
        iIndex = 1
        for m,i in sorted(list(dC[iCity])):
            oAns.append((i,'{:06}{:06}'.format(iCity,iIndex)))
            iIndex += 1
    oAns.sort()
    oAns2 =[]
    for i,s in oAns:
        oAns2.append(s)
    print("\n".join(oAns2))
解()


Measured memory_bytes: 64404
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
ll z = 1000000007 ;
/*ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b){if(b == 0) return 1 ; ll c = power(a , b/2) ; if(b%2 == 0) return ((c*c)%z) ; else return ((((c*c)%z)*a)%z) ;}
ll inverse(ll a ,ll n){return power(a , n-2) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}*/
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	ll n ;
	cin >> n ;
	ll start = -10000000000 ;
	vector<pair<ll ,ll> > v , act ;
	fo(i , n)
	{
		ll a , b ;
		cin >> a >> b ;
		v.pub(mp(a+b , a-b)) ;
	}
	sort(v.begin() , v.end()) ;
	fo(i , n)
	{
		act.pub(mp(v[i].second , v[i].first)) ;
	}
	ll ind = 0 , ans = 0;
	while(ind < n)
	{
		if(act[ind].first >= start)
		{
			ans++ ;
			start =  act[ind].second ;
          //cout << start << endl ;
		}
		ind++ ;
	}
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 6000
V, E, r = map(int, input().split())

INF = 2 << 21
G = [[] for i in range(V)]
dist = [INF for j in range(V)]


def bellman_ford(s):
    p, flg = [-1 for i in range(V)], [False for i in range(V)]
    dist[s], flg[s], cnt = 0, True, 0

    while True:
        if cnt >= 2 * V:
            return False

        on = []
        for i in range(V):
            if flg[i]:
                on.append(i)
                flg[i] = False

        if len(on) == 0:
            return True

        for i in on:
            for j in G[i]:
                if dist[i] + j[1] < dist[j[0]]:
                    dist[j[0]] = dist[i] + j[1]
                    p[j[0]], flg[j[0]] = i, True

        cnt += 1


def main():
    for i in range(E):
        s, t, d = map(int, input().split())
        G[s].append((t, d))

    check = bellman_ford(r)

    if check:
        for i in range(V):
            if dist[i] == INF:
                print("INF")
            else:
                print(dist[i])
    else:
        print("NEGATIVE CYCLE")


if __name__ == '__main__':
    main()



Measured memory_bytes: 6068
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
public class Main {
    
    public static final int m = (int)1e9+7;
    
    public static void main(String args[] ) throws Exception {
        StringBuffer str = new StringBuffer();
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] c = new char[h][w];
        for(int i=0;i<h;i++)
            c[i] = sc.next().toCharArray();
        
        long[][] dp = new long[h][w];
        for(int i=1;i<h;i++){
            if(c[i][0]=='.'){
                dp[i][0] = 1;
            } else 
                break;
        }
        for(int i=1;i<w;i++){
            if(c[0][i]=='.'){
                dp[0][i] = 1;
            } else 
                break;
        }
        for(int i=1;i<h;i++){
            for(int j=1;j<w;j++){
                if(c[i][j]=='.'){
                    dp[i][j] = dp[i-1][j]+dp[i][j-1];
                    if(dp[i][j]>=m)
                        dp[i][j]-=m;
                }
            }
        }
        
        
        str.append(dp[h-1][w-1]);
        
        
        pw.println(str.toString());
        
        pw.close();
    }
    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   public static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
}

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

int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());

    cout << fabs(a[1] - a[2]) + fabs(a[0] - a[1]) << endl;
    return 0;
}

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

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

/*
 
 4/26/2020
 
 17:20-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,K;

void solve() {
  const LL Inf=1e18;
  LL res=-Inf;
  REPE(x,N)REPE(y,N)if(x+y<=K&&x+y<=N) {
    dump(x,y);
    VI xs;
    REP(i,x) xs.push_back(A[i]);
    REP(j,y) xs.push_back(A[N-1-j]);
    sort(ALL(xs)),reverse(ALL(xs));
    int rem=K-x-y;
    while(SZ(xs)&&rem--&&xs.back()<0) xs.pop_back();
    LL sum=accumulate(ALL(xs),0LL);
    dump(x,y,sum);
    SMAX(res,sum);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=500050;
ll a[maxn],b[maxn],f1[maxn],f2[maxn],n,m,k,f=0;
int main()
{
	cin>>n>>m>>k;
	f1[0]=0;f2[0]=0;
	for(int i=1;i<=n;++i)
	  {
	  	  cin>>a[i];
		  f1[i]=f1[i-1]+a[i];
      }
	for(int i=1;i<=m;++i)
	  {
	  	  cin>>b[i];
	  	  f2[i]=f2[i-1]+b[i];
	  }
	int j=m;  
	ll ans=0;
	for(int i=0;i<=n;++i)
	  {
	  	  while(f1[i]+f2[j]>k&&j>=0)
	  	    j--; 
	  	  //cout<<i<<" "<<j<<" "<<f1[i]<<" "<<f2[j]<<endl;  
	  	  if(j>=0&&f1[i]+f2[j]<=k) 
		  {
		  	  if(i+j>ans) ans=i+j;
		  }	  
	  }
	cout<<ans<<endl;  
}


Measured memory_bytes: 9864
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
R = ri()
G = ri()
print(G+(G-R))

Measured memory_bytes: 63084
from fractions import gcd
def main():
    a, b, c = map( int, input().split())
    if a == b == c:
        if a%2 == 1:
            print("0")
        else:
            print("-1")
        return
    ans = 0
    bi = 2
    while a%bi == 0 and b%bi == 0 and c%bi == 0:
        a, b, c = a//2+b//2, b//2+c//2, c//2+a//2
        ans += 1
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 5044
n=int(input())
xy=[[] for i in range(n)]

for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=map(int,input().split())
    xy[i].append([x,y])

ans=0
for i in range(1<<n):
  cnt=bin(i).count("1")
  ok=True
  for j in range(n):
    if ok==False:break
    if i&(1<<j):
      for x,y in xy[j]:
        if y==1 and i&(1<<x-1)==0:
          ok=False
        if y==0 and i&(1<<x-1):
          ok=False
  if ok:
    ans=max(cnt,ans)
print(ans)



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

const int N = 200;
int p[N] = { 0 };
int t[3][N] = { { 0 } };
int c[3][N / 2] = { { 0 } };

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;++i){
		for(int j = 0;j < 3;++j){
			cin >> t[j][i];
			c[j][t[j][i]]++;
		}
	}
	for(int i = 0;i < 3;++i){
		for(int j = 0;j < n;++j){
			if(c[i][t[i][j]] == 1){
				p[j] += t[i][j];
			}
		}
	}
	for(int i = 0;i < n;++i){
		cout << p[i] << endl;
	}
	return 0;
}

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

#define pb push_back
#define ff first
#define ss second

typedef pair<int, int> pii;

const int MAXN = 200 * 1000 + 1, MAXS = 2 * 1000 + 17, mod = 1e9 + 7;

int sum(int a, int b) {
	a += b;
	if (a >= mod) a -= mod;
	else if (a < 0) a += mod;
	return a;
}

int mul(int a, int b) {
	return (1LL * a * b) % mod;
}

int pw(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1)
			res = mul(a, res);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int n, dp[MAXS << 1][MAXS << 1], x[MAXN], y[MAXN], p[MAXS << 1][MAXS << 1], ans, fac[MAXN], ifac[MAXN];
vector<pii> all;

void prep() {
	fac[0] = 1;
	for (int i = 1; i < MAXN; i++)
		fac[i] = mul(fac[i - 1], i);
	for (int i = 1; i < MAXN; i++)
		ifac[i] = pw(fac[i], mod - 2);
}

int C(int a, int b) {
	return mul(fac[a], mul(ifac[b], ifac[a - b]));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	prep();
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> x[i] >> y[i], p[MAXS - x[i]][MAXS - y[i]]++;
	for (int i = 1; i < MAXS << 1; i++)
		for (int j = 1; j < MAXS << 1; j++)
			dp[i][j] = sum(sum(dp[i - 1][j], dp[i][j - 1]), p[i][j]);
	for (int i = 1; i <= n; i++)
		ans = sum(ans, dp[x[i] + MAXS][y[i] + MAXS]);
	for (int i = 1; i <= n; i++)
		ans = sum(ans, -C(2 * x[i] + 2 * y[i], 2 * x[i]));
	ans = mul(ans, pw(2, mod - 2));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 101504
//package aoj0205;

import java.util.*;

public class Main {
	public static void main(String args[]) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int[] guys = new int[5];
		int tmp = scan.nextInt();

		while (tmp != 0) {
			boolean[] check = new boolean[3];
			guys[0] = tmp;
			check[tmp-1] = true;
			for (int i = 1; i < 5; i++) {
				guys[i] = scan.nextInt();
				check[guys[i]-1] = true;
			}
			int fl = 0;
			for (int i = 0; i < 3; i++) {
				if (check[i]) {
					fl++;
				}
			}
			if (fl == 1 || fl == 3) {
				for (int i = 0; i < 5; i++) {
					System.out.println(3);
				}
			} else {
				if (!check[0]) {
					for (int i = 0; i < 5; i++) {
						if (guys[i] == 2) {
							System.out.println(1);
						} else {
							System.out.println(2);
						}
					}
				} else if (!check[1]) {
					for (int i = 0; i < 5; i++) {
						if (guys[i] == 3) {
							System.out.println(1);
						} else {
							System.out.println(2);
						}
					}					
				} else if (!check[2]) {
					for (int i = 0; i < 5; i++) {
						if (guys[i] == 1) {
							System.out.println(1);
						} else {
							System.out.println(2);
						}
					}
				}
			}	
			tmp = scan.nextInt();
		}
	}
}

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

char GetGrade(int m,int f,int r){

	int s=m+f;
	char result;
	if(s>=80){result='A';}
	if (s<80&&s>=65){result='B';}
	if(s<65&&s>=50){result='C';}
	if(s<50&&s>=30){if(r>=50){result='C';}
			else{result='D';}}
	if(s<30){result='F';}
	if(m==-1||f==-1){result='F';}
	
	return result;

	}

int main(){

	int m,f,r;

	while(1){
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1){break;}
		cout<<GetGrade(m,f,r)<<"\n";
		}

	return 0;

	}

Measured memory_bytes: 1120
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (x, y, z, k) = parse!(it, 4);
    let a: Vec<usize> = parse!(it, x);
    let b: Vec<usize> = parse!(it, y);
    let c: Vec<usize> = parse!(it, z);
    let prodsum = |a: &Vec<usize>, b: &Vec<usize>| {
        let mut ab = vec![];
        for &ai in a.iter() {
            for &bi in b.iter() {
                ab.push(ai + bi)
            }
        }
        ab
    };
    let mut ab: Vec<usize> = prodsum(&a, &b);
    ab.sort();
    ab.reverse();
    let ab = ab[..std::cmp::min(ab.len(), k)].to_vec();
    let mut abc = prodsum(&ab, &c);
    abc.sort();
    abc.reverse();
    for x in &abc[..k] {
        println!("{}", *x);
    }
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 44276
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    s = input()
    print("".join(s[i] for i in range(0, len(s), 2)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,p;cin >> n >>p;
    ll o=0,e=0;
    rep(i,n){
        ll a;cin >> a;
        if(a%2==0)e++;
        else o++;
    }
    ll ans=pow(2,e);
    ll k=0;
    ll sum=0;
    while(true){
        ll tmp=1;
        if(k>o)break;
        rep(i,k){
            tmp*=(o-i);
            tmp/=(i+1);
        }
        sum+=tmp;
       // cout << tmp <<endl;
        k+=2;
    }
    if(p==0)cout << ans*sum <<endl;
    else cout << (ll)pow(2,n)-ans*sum <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    string S;
    cin >> S;
    cout << S.substr( 0, (int)S.size() - 8 ) << endl;
    return 0;
}

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

using namespace std;

void solve(){
    int x, y;
    while(cin >> x >> y){
        if(x == 0 && y == 0){
            break;
        }else{
            if(x < y){
                cout << x << " " << y << endl;
            }else{
                cout << y << " " << x << endl;
            }
        }
    }
}

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

Measured memory_bytes: 2960
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back

int MOD = 1e9+7;
int fact[555'555];
int power(int a, int n)
{
    int res = 1;
    int now = a;
    while(n)
    {
        if (n&1)
        {
            res  = (res*now) %MOD;
        }
        n>>=1;
        now = (now*now)%MOD;
    }
    return res;
}
int inv(int a)
{
    return power(a, MOD-2);
}
int C(int n, int r)
{
    if (n < r) return 0;
    return fact[n] %MOD * inv(fact[n-r])%MOD * inv(fact[r])%MOD;
}
int P(int n, int r)
{
    if (n < r) return 0;
    return fact[n]%MOD * inv(fact[n-r])%MOD;
}

void solve()
{
    fact[0] = 1;
    forn(i, 555'555-1) fact[i+1] = fact[i] * (i+1)%MOD;
    int eq = 0;
    int n, m; cin>>n>>m;
    for (int i=0; i <= n; ++i)
    {
        int ad = C(n, i)%MOD * P(m-i, n-i)%MOD;
        if (i%2 == 0) eq = (eq + ad)%MOD;
        else eq = (eq - ad + MOD)%MOD;
    }
    int ans = P(m, n)%MOD*eq%MOD;
    cout << ans << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 7900
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i -  1) * 10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}
 
struct IoSetup {
  	IoSetup() {
    	cin.tie(nullptr);
    	ios::sync_with_stdio(false);
    	cout << fixed << setprecision(15);
  	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int N;
int x[55], y[55];

map<P, bool> mp;
map<P, bool> visited;

void dfs(int p, int q, int nx, int ny) {
	visited[{nx, ny}] = true;
	if (mp[{nx + p, ny + q}] && !visited[{nx + p, ny + q}]) dfs(p, q, nx + p, ny + q);
	if (mp[{nx - p, ny - q}] && !visited[{nx - p, ny - q}]) dfs(p, q, nx - p, ny - q);
}

int main() {
	cin >> N;
	rep (i, N) cin >> x[i] >> y[i];
	rep (i, N) mp[{x[i], y[i]}] = true;

	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}

	int ans = TEN(9);
	rep (i, N) rep2 (j, i + 1, N) {
		int p = x[i] - x[j];
		int q = y[i] - y[j];
		int sub = 0;
		for (auto &x : visited) x.se = false; 
		rep (k, N) if (!visited[{x[k], y[k]}]) {
			sub++;
			dfs(p, q, x[k], y[k]);
		}
		chmin(ans, sub);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7484
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  int flag = 0;
  int cnt = 0;
  string A="";
  string B="";
  REP(i,Q){
    int T,F;
    string C;
    cin >> T;
    if(T==2){
      cin >> F >> C;
    }
    if(T==1){
      if(flag == 0){
        flag = 1;
      }else{
        flag = 0;
      }
    }else{
      if(F==1){
        if(flag==0){
          A=C+A;
        }else{
          B=B+C;
        }
      }else{
        if(flag==0){
          B=B+C;
        }else{
          A=C+A;
        }
      }
    }
  }
  if(flag == 0){
    cout << A+S+B << endl;
  }else{
    reverse(ALL(A));
    reverse(ALL(B));
    reverse(ALL(S));
    cout << B+S+A << endl;
  }
}

Measured memory_bytes: 1512
#ref. https://atcoder.jp/contests/abc129/submissions/5906191
import numpy as np
import sys


sin = sys.stdin.buffer
H, W = map(int, sin.readline().split())
grid = [[None] * W for _ in range(H)]
for h in range(H):
    grid[h] = list(input())
grid = (np.array(grid) == ".") * 1

L = np.empty((H, W), dtype="i4")
R = np.empty((H, W), dtype="i4")
T = np.empty((H, W), dtype="i4")
B = np.empty((H, W), dtype="i4")

T[0] = grid[0]
for i in range(1, H):
    T[i] = (T[i - 1] + 1) * grid[i]

B[-1] = grid[-1]
for i in range(H - 2, -1, -1):
    B[i] = (B[i + 1] + 1) * grid[i]

L[:, 0] = grid[:, 0]
for i in range(1, W):
    L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

R[:, -1] = grid[:, -1]
for i in range(W - 2, -1, -1):
    R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

ans = (T + B + L + R - 3).max()
print(ans)


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

#define endl "\n"
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(),(x).end()
#define rect return 0
#define pause cout << endl; system("pause")
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define Pi acos(-1.0)
#define bitcount __builtin_popcountll

#define TupleGet(name, index) std::get<(index)>(name)
#define FOR(a, b, c) for(int (a) = (b); (a) < (c); ++(a))
#define FORs(a, b, c) for(int (a) = (b); (a) <= (c); ++(a))
#define revFOR(a, b, c) for(int (a) = (b); (a) > (c); --(a))
#define revFORs(a, b, c) for(int (a) = (b); (a) >= (c); --(a))
#define foreach(it, a) for(auto it = (a).begin(); it != (a).end(); it++)

using namespace std;

// *** TYPEDEF'S, CONSTANTS AND FUNCTIONS *** //
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tii;
typedef vector<vector<int> > vvi;

/* |T| |I| |P| |S|
@ string abc = "abcdefghijklmnopqrstuvwxyz";
@ 'char' - 'a' ::: порядковый номер латинской буквы
@ 'digit' - '0' or 'digit' - 48 ::: (char) ---> (int)
@ 'A' = dec 65 'Z' = dec 90
  'a' = dec 97 'z' = dec 122
  '0' = dec 48 '9' = dec 57
@ Если страдает скорость ввода:
1) ios::sync_with_stdio(0);
   cin.tie(0);
2) юзать сканф
@ для стринга перевод i-того символа в другой регистр: a[i] = char (a[i] +- 32)  :::  32 == 'a' - 'A'
@ int n (m знаков) :::  n[1] = n / 10^(m-1) ; n[m] = n % 10 ; n[m-1] = (n % 100)/10 ; n[m-2] = (n % 1000)/100...
@ cout << fixed << setprecision(n) ::: n знаков после запятой, без "fixed" - всего n знаков
@ abs(x-y) < EPS ::: равентсво вещественных чисел x и y по точности EPS
@ x + EPS < y  или  x - EPS < y ::: сравнение больше-меньше для вещественных чисел по точности EPS
@ если цифру можешь записать из головы - так и пиши в программе, иначе - пиши ФОРМУЛУ
@ «экспонента» - целое число, показывающее, на сколько надо сдвинуть десятичную запятую в числе ::: 123e2 = 12300 , 123e-4 = 0.0123
@ если задача плохо решается при нумерации с единицы, иногда оказывается намного проще перейти к нумерации с нуля.
  Особенно задачах, где явно надо делить на равные части.
@ while(cin >>)  |||  while (getline(cin, )) ::: считывание, пока даются данные
@ ctrl+Z ::: конец файла в консоли
@ Глобальные массивы, чтобы не было ошибок; размер брать с запасом
@ Количество цифр N числа X в b-ичной записи, N = floor[ log[b](X) ] + 1
@ ios::sync_with_stdio(0); //ввод
@ cin.tie(0); cout.tie(0); //могут быть проблемы в интерактивных задачах (частый ввод-вывод)
*/

void A() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (auto &i : a) {
        cin >> i;
    }

    unordered_map<long long, int> prefix_sums;
    prefix_sums[0] = 1;

    long long ans = 0, curr_sum = 0;
    for (int i = 0; i < n; i++) {
        curr_sum += a[i];
        ans += prefix_sums[curr_sum];
        prefix_sums[curr_sum]++;
    }

    cout << ans;
}

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

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

int main() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans = 0;
    if (k-a > 0) {
        k -= a;
        ans += a;
    } else if (k-a == 0){
        ans += a;
        cout<<ans<<endl;
        return 0;
    } else {
        ans += k;
        cout<<ans<<endl;
        return 0;
    }
    if (k-b > 0) {
        k -= b;
    } else if (k-b == 0){
        cout<<ans<<endl;
        return 0;
    } else {
        cout<<ans<<endl;
        return 0;
    }
    if (k-c > 0) {
        k -= c;
        ans -= c;
    } else if (k-c == 0){
        ans -= c;
        cout<<ans<<endl;
        return 0;
    } else {
        ans -= k;
        cout<<ans<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
N, M, Q = map(int, input().split())
C = [[0]*N for _ in range(N)]
for _ in range(M):
    L, R = map(int, input().split())
    C[L-1][R-1] += 1
S = [[0]*(N+1) for _ in range(N+1)]
for r in range(N):
    for l in reversed(range(N)):
        S[l][r] = S[l+1][r] + C[l][r]
D = [[0]*(N+1) for _ in range(N+1)]
for l in range(N):
    for r in range(N):
        D[l][r] = D[l][r-1] + S[l][r]
for _ in range(Q):
    p, q = map(int, input().split())
    print(D[p-1][q-1])


Measured memory_bytes: 82232
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}


int main(){

	ll x;
	cin>>x;
	cout<<!x;
	
	

	
	
}

Measured memory_bytes: 3616
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 1e-8
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
using uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<cat> A(N+1);
	for(int i = 0; i <= N; i++) cin >> A[i];
	vector<cat> minv(N+1, 0), maxv(N+1, 0);
	minv[N] = maxv[N] = A[N];
	for(int i = N-1; i >= 0; i--) {
		// v[i] vertices on level i
		// v[i] >= A[i], v[i]-A[i] <= v[i+1] <= 2(v[i]-A[i])
		// (v[i+1]+1)/2 + A[i] <= v[i] <= v[i+1] + A[i]
		minv[i] = (minv[i+1]+1)/2+A[i];
		maxv[i] = maxv[i+1]+A[i];
	}
	if(minv[0] > 1 || maxv[0] < 1) {
		cout << "-1\n";
		return 0;
	}
	vector<cat> v(N+1, 0);
	v[0] = 1;
	for(int i = 0; i < N; i++) {
		if(v[i] < A[i]) {
			cout << "-1\n";
			return 0;
		}
		v[i+1] = min(2*(v[i]-A[i]), maxv[i+1]);
		if(v[i+1] < minv[i+1]) {
			cout << "-1\n";
			return 0;
		}
	}
	cat ans = 0;
	for(int i = 0; i <= N; i++) ans += v[i];
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 6368