akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(8001)
s = input()
X, Y = map(int, input().split())
S = list(map(len, s.split('T')))
N = len(S)
# if N == 1:
#   print(['No', 'Yes'][X == S[0] and Y == 0])
#   exit()
# elif N == 2:
#   print(['No', 'Yes'][X == S[0] and abs(Y) == S[1]])
#   exit()

x = S[0]
y = 0
xmoves = S[2::2]
xmoves.sort()
xmoves.reverse()
ymoves = S[1::2]
ymoves.sort()
ymoves.reverse()

def process(a, l, i, v, d, memo, r):
  if (i,v) in memo:
    return False
  if l == i:
    return v == d
  ab = abs(d-v)
  if ab > r:
    ret = False
  elif a == r:
    ret = True
  else:
    ret = process(a, l, i+1, v+a[i], d, memo, r-a[i]) or process(a, l, i+1, v-a[i], d, memo, r-a[i])
  memo[(i,v)] = ret
  return ret

if process(xmoves, len(xmoves), 0, x, X, {}, sum(xmoves)) and process(ymoves, len(ymoves), 0, y, Y, {}, sum(ymoves)):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 112584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

struct status {
    int cost;
    int v;

    bool operator<(const status &another) const { return cost < another.cost; };

    bool operator>(const status &another) const { return cost > another.cost; };
};

const int INF = 1145141919;

int dijkstra(vector<int> s, vector<int> e, int n, vector<vector<int>> &graph) {
    priority_queue<status, vector<status>, greater<>> que;
    vector<int> dis(n, INF);
    dis[s[0]] = 0, dis[s[1]] = 0;
    que.push({0, s[0]}), que.push({0, s[1]});

    while (!que.empty()) {
        status now = que.top();
        que.pop();

        if (dis[now.v] < now.cost)continue;

        for (auto next:graph[now.v]) {
            if (dis[next] > dis[now.v] + 1) {
                dis[next] = dis[now.v] + 1;
                que.push({dis[next], next});
            }
        }
    }

    int ret = min(dis[e[0]], dis[e[1]]);
    if (ret == INF)return -1;
    return ret + 1;
}

int main() {
    int x, y, z, n, m, s, t;
    cin >> x >> y >> z >> n >> m >> s >> t;

    vector<vector<int>> graph(x + y + z);
    vector<int> start;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        a = a - 1, b = x + b - 1;
        graph[a].push_back(b);
        graph[b].push_back(a);

        if (i == s - 1)start = {a, b};
    }
    vector<int> end;
    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        c = x + c - 1, d = x + y + d - 1;
        graph[c].push_back(d);
        graph[d].push_back(c);

        if (i == t - 1)end = {c, d};
    }

    cout << dijkstra(start, end, x + y + z, graph) << endl;
    return 0;
}



Measured memory_bytes: 18148
n=int(input())
S=input()
ans=S
stack=[]
for i in range(len(S)):
  if S[i]=="(":
    stack.append("(")
  else:
    if len(stack)==0:
      ans="("+ans
    else:
      stack.pop()
ans+=")"*len(stack)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
using namespace std;
int dx1[6]={-1,0,0,1,1,1};
int dy1[6]={0,1,-1,1,0,-1};
int dx2[6]={-1,-1,-1,0,0,1};
int dy2[6]={-1,0,1,-1,1,0};
int X[102][102];
int W,H;
bool F[102][102];
void g(int x,int y){
	if(y%2==0){
		for(int i=0;i<6;i++){
			if(dx2[i]+x>=0&&dx2[i]+x<=W+1&&dy2[i]+y>=0&&dy2[i]+y<=H+1){
				if(X[x+dx2[i]][y+dy2[i]]==0&&!F[x+dx2[i]][y+dy2[i]]){
					F[x+dx2[i]][y+dy2[i]]=true;
					g(x+dx2[i],y+dy2[i]);
				}
			}
		}
	}
	else{
		for(int i=0;i<6;i++){
			if(dx1[i]+x>=0&&dx1[i]+x<=W+1&&dy1[i]+y>=0&&dy1[i]+y<=H+1){
				if(X[x+dx1[i]][y+dy1[i]]==0&&!F[x+dx1[i]][y+dy1[i]]){
					F[x+dx1[i]][y+dy1[i]]=true;
					g(x+dx1[i],y+dy1[i]);
				}
			}
		}
	}
}
int main()
{
	scanf("%d%d",&W,&H);
	for(int i=0;i<=H+1;i++)for(int j=0;j<=W+1;j++){
		F[j][i]=false;
		X[j][i]=0;
	}
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			scanf("%d",&X[j][i]);
		}
	}
	
	for(int i=0;i<=W+1;i++){
		F[i][0]=true;
		F[i][H+1]=true;
	}
	for(int i=0;i<=H+1;i++){
		F[0][i]=true;
		F[W+1][i]=true;
	}
	for(int i=0;i<=H+1;i++)for(int j=0;j<=W+1;j++){
		if(i==0||i==H+1||j==0||j==W+1)g(j,i);
	}
	int ans=0;
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			int l=0;
			if(X[j][i]==1){
				if(i%2==0){
					for(int k=0;k<6;k++){
						if(F[j+dx2[k]][i+dy2[k]])l++;
					}
				}
				else{
					for(int k=0;k<6;k++){
						if(F[j+dx1[k]][i+dy1[k]])l++;
					}
				}
			}
			ans+=l;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1428
//09/02/2020
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b push_back
#define m_p make_pair

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
vector<ll>v;


int main(){
    _fastio
    string s1,s2,t;
    cin>>s1>>s2;

    ll a,b;
    cin>>a>>b;
    cin>>t;
    if(s1==t){
        cout<<a-1<<' '<<b<<endl;
    }
    else{
        cout<<a<<' '<<b-1<<endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define timeKyaHorhaH 1.0 * clock() / CLOCKS_PER_SEC
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define mkp make_pair
#define pb push_back
#define endl '\n'
#define mod 1000000007
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld n,ans=0;
	cin>>n;

	FORG(i,1,n+1)
	{
		if(i%3==0 || i%5==0)
			continue;
		ans+=i;
	}

	cout<<ans;
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();
	
	// cerr<<"\n"<<timeKyaHorhaH; 	
 	return 0;
}

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

int main(){
  int a, b, c;
  string ans = "NO";
  cin >> a >> b >> c;
  
  for (int i=0; i<b; i++) {
    if (i*a % b == c) {
      ans = "YES";
      break;
    }
  }
  
  cout << ans << endl;
      
  return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  int N;
  cin >> N;
  REP(i, 10) {
    if (1000*(i+1) >= N) {
      cout << 1000*(i+1) - N << endl;
      return 0;
    }
  }
}

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

using namespace std;

int main(void)
{
    int savers_count;
    vector<int> monsters_counts;
    vector<int> capacities;

    cin >> savers_count;

    for(int i = 0; i < savers_count + 1; i++){
        int m;
        cin >> m;
        monsters_counts.push_back(m);
    }

    for(int i = 0; i < savers_count; i++){
        int c;
        cin >> c;
        capacities.push_back(c);
    }

    long long defeats_count = 0;
    for(int i = 0; i < savers_count; i++){
        defeats_count += min(monsters_counts[i], capacities[i]);

        const int exceed = capacities[i] - monsters_counts[i];
        if(exceed > 0){
            const int extra_defeats = min(monsters_counts[i + 1], exceed); 
            monsters_counts[i + 1] -= extra_defeats;
            defeats_count += extra_defeats;
        }
    }

    cout << defeats_count << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  ll N,K,Q;
  scanf("%lld%lld%lld", &N,&K,&Q);
  ll a[Q];
  for (int i = 0; i < Q; ++i) {
    scanf("%lld", &a[i]);
  }

  ll point[N];
  FOR(i,0,N-1) point[i] = K-Q;

  FOR(i,0,Q-1){
    ++point[a[i]-1];
  }

  FOR(i,0,N-1){
      if(point[i]>0) cout << "Yes" << endl;
      else cout << "No" << endl;
  }

}



Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tst lli T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main()
{
	vite;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	string s,t;
	cin>>s>>t;
	lli m=MAX;
	lli k=0;
	for(lli i=0;i<s.length()-t.length()+1;i++)
	{
		for(lli j=0;j<t.length();j++)
		{
			if(s[i+j]!=t[j]) k++;
		}
		// cout<<k<<" ";
		m=min(m,k);
		k=0;
	}
	cout<<m;
	cout<< endl;
	// cout<< fixed << setprecision(6) << 1.0 * clock() / CLOCKS_PER_SEC;
	return 0;
}

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

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        String s = br.readLine();
        StringBuilder ans = new StringBuilder();
        for (int i=0; i<s.length(); i++){
            if (i%2 == 0){
                ans.append(s.charAt(i));
            }
        }
        System.out.println(ans.toString());

    }

}



Measured memory_bytes: 34904
import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const s = inputs[0];
  const t = inputs[1];
  
  if (t.length === s.length + 1
      && s === t.substring(0,s.length)) {
        console.log('Yes');
        return;
  }
  console.log('No');
}


Measured memory_bytes: 29964
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans = 0
    P = []
    v = 0
    for a, b in zip(A, B):
        if a >= b:
            P.append(a - b)
        else:
            v += b-a
            ans += 1
    P.sort(reverse=True)

    for p in P:
        if v <= 0:
            break
        v -= p
        ans += 1
    if v <= 0:
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()


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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    int N;
    string S;
    cin >> N;
    cin >> S; 
   
    int ans = 1;
    REP(i, N-1) {
        if (S[i] == S[i+1]) {
            continue;
        } else {
            ans += 1;
        }
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
/*
bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < pri_max; i++)
	{
		if (memo[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l < pri_max; l += i)
			{
				memo[l] = true;
			}
		}
	}
}*/
int main()
{
	int ans = 0;
	string a,b;
	while (cin >> a)
	{
		b = a;
		reverse(all(b));
		if (a == b)ans++;
	}
	cout << ans << endl;

}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    string s;
    cin>n>s;
    int c=0;
    REP(i,n){
        if(s[i]=='R')c++;
        else c--;
    }
    Yes(c>0);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;
    
int dy[4]={1, -1, 0, 0};
int dx[4]={0, 0, 1, -1};

int32_t main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ans_1, ans_2=ans_1=0;
    if(a+b>c*2){
        REP(i, x){
            ans_1+=c*2;
        }
        if(y-x>0){
            REP(i, y-x){
                ans_1+=b;
            }
        }
        REP(i, y){
            ans_2+=c*2;
        }
        if(x-y>0){
            REP(i, x-y){
                ans_2+=a;
            }
        }
        cout << min(ans_1, ans_2) << endl;
    }
    else{
        int ans=0;
        REP(i, x) ans+=a;
        REP(i, y) ans+=b;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
typedef long long ll;
ll inf = 1e9;
using namespace std;
ll dp[100005];
ll h[100005];
int main() {
	int h, w;
	cin >> h >> w;
	int c[25][25] = {};
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> c[i][j];
		}
	}
	int a[205][205];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	for (int k = 0; k < 10; k++) {
		for (int i = 0; i <10 ; i++) {
			for (int j = 0; j <10 ; j++) {
				if (c[i][j] > c[i][k] + c[k][j]){
				   c[i][j] = c[i][k] + c[k][j];
				}
			}
		}
	}
	int count = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] != -1) {
				count += c[a[i][j]][1];
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

int main(){

  int m,a,b,t=0,s;

  while(cin>>m>>a>>b){
    t=0;
    if(m==0){
      break;
    }

  int p[m];
  for(int i=0;i<m;i++){
    cin>>p[i];
  }

  for(int i=a;i<=b;i++){
    if(t<=p[i-1]-p[i]){
      t=p[i-1]-p[i];
      s=i;
    }
  }
  

  cout<<s<<endl;

  }

  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 200011
#define maxH 555

int n, h, i;
int a, b, c, d, l, r;
vector<int> list[maxH];
int in[maxH], out[maxH];
bool us[maxN], any;

void no_sol() {
    printf("NO");
    exit(0);
}

void dfs(int node) {
    us[node] = true;
    if (in[node] != out[node]) any = true;
    if (in[node] == 0 && out[node] == 0) any = true;
    for (auto to : list[node])
        if (!us[to])
            dfs(to);
}

int main()
{
 //   freopen("test.in","r",stdin);

    scanf("%d%d", &n, &h);
    for (i = 1; i <= n; i++) {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        if (c == 0) l = a;
        else        l = -c;

        if (d == 0) r = -b;
        else        r = d;

        l += h;
        r += h;
        list[l].pb(r);
        list[r].pb(l);
        in[r]++;
        out[l]++;
    }

    for (i = 1; i <= h; i++)
        if (out[i + h] < in[i + h])
            no_sol();

    for (i = 1; i <= h; i++)
        if (out[-i + h] > in[-i + h])
            no_sol();

    for (i = 1; i <= h; i++) {
        if (!us[i + h]) {
            any = false;
            dfs(i + h);
            if (!any) no_sol();
        }

        if (!us[-i + h]) {
            any = false;
            dfs(-i + h);
            if (!any) no_sol();
        }
    }


    printf("YES");

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

ll dp[100005];
ll pow2(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b%2 == 1) ans = ans*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return ans;
}
int main(){
    int n, k;
    scanf("%d%d", &n, &k);

    vector<int> f;
    for(int i=1;i*i<=n;i++){
        if(n%i == 0){
            f.eb(i);
            if(n/i != i) f.eb(n/i);
        }
    }   
    sort(all(f));
    ll ans = 0;
    for(int i=0;i<sz(f);i++){
        dp[i] = pow2(k, (f[i]+1)/2);
        for(int j=0;j<i;j++){
            if(f[i]%f[j] == 0){
                dp[i] = (dp[i] - dp[j] + mod)%mod;
            }
        }
        if(f[i]%2 == 0) ans = (ans + dp[i]*1ll*f[i]/2)%mod;
        else ans = (ans + dp[i]*1ll*f[i])%mod;
    }
    printf("%lld\n", ans);
}

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

using namespace std;

#define int long long

const int N = 2e3 + 100, MOD = 1e9 + 7;

int dp[N][N], a[N], b[N];
int n, m;

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
	cin >> a[i];
    for (int i = 1; i <= m; i++)
	cin >> b[i];
    for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++)
	    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + (a[i] == b[j]) * (dp[i - 1][j - 1] + 1)) % MOD;
    return cout << (dp[n][m] + 1 + 23 * MOD) % MOD, 0;
}

Measured memory_bytes: 33152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    intf n,l;
    cin >>n >>l;

    vector<string> s(n);
    for(auto &e:s) cin >>e;

    sort(s.begin(),s.end());

    for(auto &e:s) cout <<e;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int day, sumptn = 0;
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] plan = new int[N];
		int[][] pattern = new int[N][6];
		for(int i = 0; i < K; i++) {
			day = sc.nextInt();
			plan[day-1] = sc.nextInt();
			}
		if(plan[0] == 0) {
			for(int i = 0; i < 3; i++) pattern[0][i] = 1;
		}
		else pattern[0][plan[0]-1] = 1;
		
		for(int i= 1; i < N; i++) {
			for(int k = 0; k < 6; k++) sumptn += pattern[i-1][k]%10000;

				if(plan[i] == 0) {//予定がない場合
					for(int j = 0; j < 6; j++) {
					if(j<3) pattern[i][j] = (sumptn-pattern[i-1][j]-pattern[i-1][j+3])%10000;
					else pattern[i][j] = pattern[i-1][j-3];
					}
				}
					else {//予定がある場合
						pattern[i][plan[i]-1] = (sumptn-pattern[i-1][plan[i]-1]-pattern[i-1][plan[i]+2])%10000;
						pattern[i][plan[i]+2] = pattern[i-1][plan[i]-1];
				
				}
				sumptn = 0;
				if(i == N-1) for(int k = 0; k < 6; k++) sumptn += pattern[N-1][k]%10000;
		}
		System.out.println(sumptn%10000);
	}
}

Measured memory_bytes: 19680
#include <stdio.h>

void printBin(int n, int d);

int main(void){
    int ptn[] = {63, 6, 91, 79, 102, 109, 125, 39, 127, 111};
    int cur, next, n;
    
    while(scanf("%d",&n), n!=-1){
        cur=0;
        for (int i=0; i<n; i++){
            scanf("%d", &next);
            printBin(cur^ptn[next], 7);
            printf("\n");
            cur = ptn[next];
        }
    }
    return 0;
}

void printBin(int n, int d){
    for (d--; d>=0; d--){
        printf("%d", (n>>d)&1);
    } 
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    cin >> n >> m;
    int d[n][n];
    int a[m], b[m], c[m];

    int INF = 1e7;

    rep(i, n) rep(j, n) d[i][j] = (i == j ? 0 : 1e7);

    rep(i, m)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }

    rep(k, n)
    {
        rep(i, n)
        {
            rep(j, n)
            {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int cnt = 0;

    /*
    rep(t, m)
    {
        bool flag = 0;
        rep(i, n)
        {
            rep(j, n)
            {
                if (d[i][j] == d[i][a[t]] + c[t] + d[b[t]][j])
                    flag = 1;
            }
        }
        if (!flag)
            cnt++;
    }*/

    rep(t, m) if (d[a[t]][b[t]] != c[t]) cnt++;

    OP(cnt);

    return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  int ans = 0;
  bool ok = true;
  int cntb = 0, cntw = 0;
  for(int i = n-1; i >= 0; i--){
    if(s.at(i) == '.') ok = false;
    if(ok) continue;
    if(s.at(i) == '#') cntb++;
    else if(cntb == 0) cntw++;
    else{
      if(cntw <= cntb){
        ans += cntw;
        cntb = 0, cntw = 1;
      }
      else cntw++;
    }
  }
  ans += min(cntb, cntw);
  
  cout << ans << endl;
}

Measured memory_bytes: 640
/* 
 * Author: aps
 * Time: 2020-01-26 22:48:51
**/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
 
using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
 
const ll inf = 1e18;
const ll mod = 1e9+7;
 
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll gcd(ll x, ll y) { return x == 0 ? y : gcd(y % x, x); }
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MX = 2e4+4;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int h,n; cin >> h >> n;
    vi a(n+1,0), b(n+1,0);

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

    vvi dp(n+1, vi (h+1, 1e8));
    dp[0][0] = 0;
    for(int i=0; i<=n; i++) dp[i][0] = 0;

    for(int i=1; i<=n; i++) {
        for(int j=1; j<=h; j++) {
            int val = dp[i][j];
            int prev = max(0, j-a[i]);
            val = min(val, dp[i][prev] + b[i]);
            val = min(val, dp[i-1][j]);
            dp[i][j] = val;
        }
    }

    cout << dp[n][h] << "\n";
    return 0;
}




















Measured memory_bytes: 39424
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

let choice ok ng bool = if bool then ok else ng

readIntArray ()
|> fun [| x; all |] ->
    [ 0 .. x ]
    |> List.map (fun y -> y * 2 + (x - y) * 4)
    |> List.exists (fun x -> x = all)
    |> choice "Yes" "No"
    |> printfn "%s"


Measured memory_bytes: 29704
while True:
    a,op,b = input().split()
    A = int(a)
    B = int(b)
    if op == "+":
        print(A + B)
    elif op == "-":
        print(A - B)
    elif op == "*":
        print(A * B)
    elif op == "/":
        print(A // B)
    else:
        break

Measured memory_bytes: 7616
#include <bits/stdc++.h>
#define MAXN 2010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e9 + 7;

int main (){
    ios_base::sync_with_stdio(false);
    string a, s , b;
    cin >> a >> s >> b;

    cout << "A" << s[0] << "C" << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BROTN {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        string S;
        in>>S;
        for(auto& s : S){
            s = char('A'+(s-'A'+N)%26);
        }
        out<<S<<'\n';
    }
};


int main() {
	BROTN solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

int main()
{
	cout <<setprecision(10);
	string s ; cin >> s;
	int n = s.size();
	int one= 0 , two = 0;
	rep(i,n){
		if(s[i] == '0'){
			two ++;
		}
		else one++;
	}
	cout << min(one,two)*2 << endl;
		

}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int res = 0;
	for (int i = 0;i < n;i++) {
		if (s[i]=='A') {
			for (int j = n-1;j>=i;j--) {
				if (s[j] == 'Z') {
					res = j - i + 1;
					break;
				}
			}
			break;
		}
	}
	cout << res << endl;
	
}

Measured memory_bytes: 640
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>
#include<stack>
#include <cstdlib>


using namespace std;

int main() {
	int a, b;
	int tmp1=0,tmp2=0;
	cin >> a >> b;

	if (a > b) {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
	}
	else {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
long long  a,b,c;
int main() 
{
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0) {
        cout<<0;
        return 0;
    }
    cout<<min(min(a*b,a*c),b*c);
    return 0;
}

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

// 累積和
struct cumulative_sum {
    using lint = long long int;
    int sz;
    // data[i]:元の数列
    vector<lint> data;
    // cum[i]:[0,i)の和
    vector<lint> sum;
    // 要素数を指定して初期化
    cumulative_sum(const int _sz) : sz(_sz) {
        data.assign(sz, 0);
        sum.assign(sz + 1, 0);
    }
    lint &operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + data[i];
    }
    // [a,b)の和を求める
    lint query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    int n;
    cin >> n;
    cumulative_sum a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a.build();
    lint ans = LLONG_MAX;
    // i:取る枚数
    for (int i = 1; i < n; i++) {
        lint x = a.query(0, i);
        lint y = a.query(i, n);
        chmin(ans, abs(x - y));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6340
n=int(input())
a = n // 3
b = n // 5
c = n // 15

x = a * 3
y = b * 5
z = c * 15

s = (3 + x) * a // 2
t = (5 + y) * b // 2
u = (15 + z) * c // 2

souwa = (n + 1) * n // 2
print(souwa - s - t + u)




Measured memory_bytes: 9184
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
l = list(map(int, input().split()))

x = sum(l[:k])
max_val = x
for i in range(n-k):
    x = x-l[i]+l[i+k]
    if x > max_val:
        max_val = x

print((max_val+k)*1.0/2)

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	int n = ri();
	int a[n]; INPUT(a);
	FOR(i,n) a[i] -= i;
	SORT(a);
	int m = a[n/2];
	s64 res = 0;
	FOR(i,n) res += abs(a[i]-m);
	cout << res << endl;
	
    return 0;
}


Measured memory_bytes: 1788
N,K = string.match(io.read(), "(%d+) (%d+)")
N,K = tonumber(N), tonumber(K)

t = {}
for i = 0, N-1, 1 do t[i+1] = 0 end

for i = 0, K-1, 1 do
	d = io.read("*number")
	for j = 0, d-1, 1 do
		A = io.read("*number")
		t[A] = t[A] + 1
	end
end

ans = 0
for i = 0, N-1, 1 do
	if t[i+1] == 0 then
		ans = ans + 1
	end
end

print(ans)

Measured memory_bytes: 2792
import java.io.*;
import java.util.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, m, k;
	static long mod = 998244353;
	static Boolean[][][] memo;
	static String s;
	static HashSet<Integer> nodes;
	static ArrayList<Integer>[] ad;
	static boolean[] vis;
	static TreeSet<Long> al;
	static int[][] val;
	static int[] b;
	static int ans;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int a = sc.nextInt();
		long b = sc.nextLong();
		long n = sc.nextLong();
		long ans = (n * a) / b - a * (n / b);
		if(b-1<n)
			ans=Math.max(ans, ((b-1) * a) / b - a * ((b-1) / b));
		for (long i = b - 1; i <= Math.min(n, 10000000); i += b) {
			ans = Math.max(ans, (i * a) / b - a * (i / b));
		}
		for (long i = n; i >= Math.max(0, n - 10000000); i--) {
			ans = Math.max(ans, (i * a) / b - a * (i / b));
		}
		long k = n / b;
		long st = k * b;
		ans = Math.max(ans, (st* a) / b - a * (st / b));
		for (long i = st - 1; i >= Math.max(0, n - 10000000); i -= b) {
			ans = Math.max(ans, (i * a) / b - a * (i / b));
		}
		System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 33172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A;
  // N,Aを宣言
  	cin >> N >> A;
  	// 入力結果をN,Aに代入
  	cout << N*N - A << endl;
  	//　塗りつぶされたマス数を出力
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
	
	cin >> N;
	
	vector<int> T(N);
	
	rep(i, N)
		cin >> T[i];
		
	int M;
	
	cin >> M;
	
	int P, X;
	
	rep(i, M){
		cin >> P >> X;
		int ans = 0;
		rep(j, N){
			if(P == j + 1)
				ans += X;
			else
				ans += T[j];
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef pair<pll, lint> ppl;

const lint mod = 998244353;

lint powmod(lint x, lint n){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

lint gcd(lint p, lint q){
    if(p < q) swap(p, q);
    while(q){
        lint r = p % q;
        p = q;
        q = r;
    }
    return p;
}

int main(){
    int n;
    scanf("%d", &n);
    lint x[n], y[n];
    rep(i, n) scanf("%lld%lld", &x[i], &y[i]);
    
    vector<ppl> L;
    rep(i, n)For(j, i+1, n){
        lint a = y[j] - y[i];
        lint b = x[i] - x[j];
        lint c = x[i]*(y[j]-y[i]) - y[i]*(x[j]-x[i]);
        if(a < 0 || (a==0 && b < 0)) a *= -1, b *= -1, c *= -1;
        lint g = gcd(gcd(abs(a), abs(b)), abs(c));
        L.push_back(ppl(pll(a/g, b/g), c/g));
    }
    sort(L.begin(), L.end());
    L.erase(unique(L.begin(), L.end()), L.end());
    
    lint ans = (powmod(2, n)-(n+1)+mod) % mod;
    for(auto l: L){
        lint a = l.fi.fi;
        lint b = l.fi.se;
        lint c = l.se;
        int cnt = 0;
        rep(i, n)if(a*x[i]+b*y[i] == c) ++cnt;
        ans = (ans - powmod(2, cnt)+cnt+1 + mod) % mod;
    }
    
    printf("%lld\n", ans);
}

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

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
#define all(v) v.begin(),v.end()
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(N); cin >> A;
        sort(all(A));

        int n = A[N - 1];
        int r = A[0];
        int dist = 1e9;
        for(int i = 0; i < N; i++) {
            if(set_min(dist, abs(n / 2 - A[i]))) r = A[i];
            if(n % 2 == 1 and set_min(dist, abs(n / 2 + 1 - A[i]))) r = A[i];
        }
        cout << n << " " << r << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)
#define mp(a,b) make_pair(a, b)

typedef vector<int> vi;
struct P { double angle, dist; int idx; };
bool operator<(const P& p1, const P& p2) {
	if(p1.angle != p2.angle) return p1.angle < p2.angle;
	if(p1.dist != p2.dist) return p1.dist < p2.dist;
	return p1.idx < p2.idx;
}

const double PI = atan(1.0) * 4.0;

const double EPS = 1.0e-10;
const int MAX_N = 410;
int n;
int x[MAX_N], y[MAX_N];
bool used[MAX_N];

double atan3(int x1, int y1, int x2, int y2) {
	double dot = x1 * x2 + y1 * y2;
	double det = x1 * y2 - x2 * y1;
	double a = atan2(det, dot);
	return a;
}

double distance(int x1, int y1, int x2, int y2) {
	double dx = x2 - x1;
	double dy = y2 - y1;
	return sqrt(dx * dx + dy * dy);
}

void solve() {
	memset(used, 0, sizeof(used));

	vector<P> v;
	int px = 0, py = 0;
	int prevx = 0, prevy = -1;
	double dist = 0.0;
	int visit = 0;
	while(visit < n) {
		v.clear();
		rep(i,n) {
			if(!used[i]) {
				double angle = atan3(x[i]-px, y[i]-py, px-prevx, py-prevy);
				double dd = distance(px, py, x[i], y[i]);
				P p = { angle, dd, i };
				v.push_back(p);
			}
		}
		sort(v.begin(), v.end());

		int idx = v[0].idx;
		dist += v[0].dist;
		prevx = px;
		prevy = py;
		px = x[idx];
		py = y[idx];
		used[idx] = true;
		visit++;
	}
	printf("%.1f\n", dist);
}

int main() {
	while(scanf("%d", &n), n) {
		rep(i,n) scanf("%d%d", &x[i], &y[i]);
		solve();
	}
}

Measured memory_bytes: 1352
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<stack>
#include<set>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using pll = pair<ll,ll> ;
ll INF = 1e15 ;
void chmin(ll &a,ll b){if(a>b) a = b ;}
void chmax(ll &a,ll b){if(a<b) a = b ;}
void YorN(bool a){cout << (a?"YES":"NO") << "\n" ;}

ll DFS(vvll &g,int cur,int pre){
	ll res = 0 ;
	for(int i=0;i<g[cur].size();i++){
		if(pre==g[cur][i]) continue ;
		res ^= DFS(g,g[cur][i],cur)+1 ;
	}
	return res ;
}

int main(){
	ll n ; cin >> n ;
	vvll g(n) ;
	for(int i=1;i<n;i++){
		ll a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g[a].push_back(b) ;
		g[b].push_back(a) ;
	}
	cout << (DFS(g,0,-1)?"Alice":"Bob") << endl ;
}

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

int main(){
    long int A,B,k=1;
    cin>>A>>B;
    for (int i=2;i<=A;i++){
       if((A%i==0)&&(B%i==0)) k=i;
    }
    long int X;
    X=(A*B)/k;
    cout<<X<<endl;
    return 0;
}

Measured memory_bytes: 256
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, L: number } => {
  const [N, L] = lines[0].split(' ').map(line => +line)
  const obj = { N, L }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { N, L } = parseLines(lines)

  const tastes = []
  for (let i = 1; i <= N; i++) {
    const taste = L + i - 1
    tastes.push(taste)
  }
  tastes.sort((a, b) => Math.abs(a) - Math.abs(b))
  const ateTastes = tastes.splice(1, N)
  const result = ateTastes.reduce((prev, current) => prev += current, 0)
  return `${result}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7756
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int N;
vector<int> V,C;
vector<int> A;

int main()
{
  cin >> N;
  V.resize(N);
  C.resize(N);
  REP(i,0,N) cin >> V[i];
  REP(i,0,N) cin >> C[i];

  // A[i]
  A.resize(N);
  REP(i,0,N) A[i] = V[i] - C[i];

  int res = 0;
  REP(i,0,N) {
    if(A[i] > 0) res += A[i];
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (N, K) = listOfInt()
    val X = listOfInt()
    val dp = Array(N + 1) { Array(N + 1) { LongArray(N * 50 + 1) } }
    dp[0][0][0] = 1
    for (i in 0 until N) {
        for (j in 0 until N) {
            for (k in 0 until N * 50 + 1) {
                if (dp[i][j][k] == 0L) continue
                dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]
                dp[i + 1][j][k] += dp[i][j][k]
            }
        }
    }
    var ans = 0L
    for (j in 1 .. N) ans += dp[N][j][K * j]
    println(ans)

}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }



Measured memory_bytes: 109900