akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N,T;
ll dp[3005][3005]={0};
vpii datas;
int main(){
	cin>>N>>T;
	rep(i,N){
		int a,b;
		cin>>a>>b;
		datas.pb(mp(a,-b));
	}
	sort(all(datas));
	ll ans=0;
	rep(i,N){
		int a=datas[i].first;
		int b=-datas[i].second;
		//cout<<a<<" "<<b<<endl;
		//ansチェック
		for(int j=0;j<T;j++){
			ans=max(ans,dp[j][i]+b);
			dp[j][i+1]=dp[j][i];
		}
		//dp更新
		for(int j=0;j<T-a;j++){
			dp[j+a][i+1]=max(dp[j+a][i],dp[j][i]+b);
		}
	}
	cout<<ans<<endl;

}



Measured memory_bytes: 70784
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int n,k;
vector<int>v(200009);
bool possible(int mid)
{
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        int d=v[i]/mid;
        if(v[i]%mid==0)d--;
        cnt+=d;

    }
    if(cnt<=k)return true;
    return false;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   int t;
   //cin>>t;
   t=1;
   while(t--)
   {

       cin>>n>>k;
       int mx=0;
       for(int i=0;i<n;i++){cin>>v[i];mx=max(mx,v[i]);}
       if(k==0){cout<<mx<<endl;continue;}
       int low=1;
       int high=mx;
       int ans=0;
       while(low<=high)
       {
           int mid=(low+high)/2;
           if(possible(mid))
           {
               ans=mid;
               high=mid-1;
           }
           else low=mid+1;
       }
   cout<<ans<<endl;

   }
}


Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#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 all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
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};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
//cout << fixed << setprecision(12);
ll n;
cin>>n;
string a[n]={};
ll q=0,w=0,e=0,r=0;
rep(i,n){
cin>>a[i];}
rep(i,n){
if(a[i].at(0)=='A'){
q++;}
else if(a[i].at(0)=='W'){
w++;}
else if(a[i].at(0)=='T'){
e++;}
else
r++;}
cout << "AC x "<<q<<endl;
cout << "WA x "<<w<<endl;
cout << "TLE x "<<e<<endl;
cout << "RE x "<<r<<endl;}

Measured memory_bytes: 6752
import sys

lines = sys.stdin.readlines()

N = lines[0]
A = lines[1].strip().split(" ")

flag = 1

c = 0
i = 0
while flag == 1:
    flag = 0
    for j in reversed(range(i+1,len(A))):
        if int(A[j]) < int(A[j-1]):
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1
    i += 1

print " ".join(A)
print c

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

int n;
long long l;
long long a[100055];

int main() {
	scanf("%d %lld", &n, &l);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	for (int i = 0; i < n - 1; i++) {
		if (a[i] + a[i + 1] >= l) {
			puts("Possible");

			for (int j = 0; j < i; j++) printf("%d\n", j + 1);
			for (int j = n - 2; j > i; j--) printf("%d\n", j + 1);

			printf("%d\n", i + 1);
			
			return 0;
		}
	}

	puts("Impossible");

	return 0;
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a,sum,ans;
vector<int> v;

main() {
    cin >> n;
    rep(i,n) {
        cin >> a;
        sum+=a;
        v.pb(sum)
    }
    sort(all(v));
    int cnt=1;
    if(!v[0]) ans++;
    rep1(i,n-1) {
        if (!v[i]) ans++;
        if (v[i] == v[i-1]) cnt++;
        else {
            cnt--;
            rep1(i,cnt) ans += i;
            cnt=1;
        }
    }
    cnt--;
    rep1(i,cnt) ans += i;
    ct(ans)
}

Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>

using namespace std;

#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll a[6];
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
    }
    sort(a,a+5);
    if(a[0]>=n)
        cout<<"5"<<endl;
    else
    {
        ll ans;
        if(n%a[0])
            ans=n/a[0]+5;
            else
                ans=n/a[0]+4;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long i,N, sum=0;;
    cin >> N;
    for(i=1;i<=N;i++)
    {
        if((i%3==0 ||i%5==0))
        {
            continue;
        }

        else
            sum+=i;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3616
N = int(input())
L = [int(i) for i in input().split()]
L.sort()
M = [0 for i in range(2*10**3+1)]
C = [0 for i in range(2*10**3+1)]
L_num = [1]
cnt = 1
for i in range(N-1):
    if L[i+1] == L[i]:
        cnt += 1
    else:
        cnt = 1
    L_num.append(cnt)
for i in range(N):
    M[L[i]] += 1
for i in range(1, len(M)):
    C[i] = C[i-1] + M[i]
cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        a = L[i]
        b = L[j]
        cnt += C[a+b-1] - C[b-1] - L_num[j]
print(cnt)

Measured memory_bytes: 3316
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n = int(input())
p = list(map(int, input().split()))

if n == 1:
    print(1)
    exit()

MOD = 10 ** 9 + 7

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

c = p[0]
for x in p[1:]:
    c = c * x // gcd(c, x)

ans = 0
for x in p:
    ans += c // x

print(ans % MOD)


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

int main() {
	ll n;
	cin >> n;
	vector<ll> v(n);
	for (ll i = 0; i < n; ++i)cin >> v[i];
	ll ans = 1e10;
	for (ll x = 1; x <= 100; ++x) {
		ll sum = 0;
		for (ll i = 0; i < n; ++i) {
			sum += (v[i] - x) * (v[i] - x);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}


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

const int N = 500 + 10;
const int dx[] = { 1, -1, 0, 0 };
const int dy[] = { 0, 0, 1, -1 };

int n;
int dp[N][N], have[N][N];

bool in (int i, int j) { return 1 <= i && i <= n && 1 <= j && j <= n; }

void upd (int i, int j) {
	for (int k = 0; k < 4; k ++) {
		int x = i + dx[k];
		int y = j + dy[k];
		if (in(x, y) && dp[i][j] + have[i][j] < dp[x][y]) {
			dp[x][y] = dp[i][j] + have[i][j];
			upd(x, y);
		}
	}
}

int main (void) {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= n; j ++) {
			have[i][j] = 1;
			dp[i][j] = min({ i - 1, j - 1, n - i, n - j });
		}
	}
	long long ans = 0;
	for (int i = 1, x, y; i <= n * n; i ++) {
		scanf("%d", &y);
		x = (y - 1) / n + 1;
		y = (y - 1) % n + 1;
		ans += dp[x][y];
		have[x][y] = 0;
		upd(x, y);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 20904
A, B = map(int, input().split())
import fractions

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return 0
    return n

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
#            divisors.append(i)
            divisors.append(is_prime(i))
            if i != n // i:
#                divisors.append(n//i)
                divisors.append(is_prime(n//i))

    divisors.sort()
    return divisors
C = make_divisors(fractions.gcd(A, B))


#print(C)
#print(is_prime(5))
#print(is_prime(10))

print(len(C) - C.count(0) )  


Measured memory_bytes: 5176
import sys
from heapq import heappush, heappop, heappushpop

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(N, K, L, R):
    left = [[] for _ in range(N)]
    right = [[] for _ in range(N)]
    score = 0
    for k, l, r in zip(K, L, R):
        k -= 1
        if l < r:
            score += l
            right[k].append(r - l)
        else:
            score += r
            left[k].append(l - r)
    q = []
    for n, xs in enumerate(left, 1):
        for x in xs:
            if len(q) < n:
                heappush(q, x)
            else:
                heappushpop(q, x)
    score += sum(q)
    q = []
    for n, xs in enumerate(right[::-1][1:], 1):
        for x in xs:
            if len(q) < n:
                heappush(q, x)
            else:
                heappushpop(q, x)
    score += sum(q)
    return score

T = int(readline())
for _ in range(T):
    N = int(readline())
    K, L, R = [], [], []
    for _ in range(N):
        k, l, r = map(int, readline().split())
        K.append(k)
        L.append(l)
        R.append(r)
    print(main(N, K, L, R))


Measured memory_bytes: 70404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var h = (from s in Console.ReadLine().Split(' ') select int.Parse(s)).ToList();

            int ret = 0;
            int cur = -1;

            foreach (int i in h)
            {
                if (cur <= i)
                    ret++;
                cur = Math.Max(cur, i);
            }
            Console.WriteLine("{0}", ret);
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int a,b,k=1,t=1,x,y;
		int i=1,j=1;
		while(s.hasNext()){
			a=s.nextInt();
			b=s.nextInt();
			//
			k=a;t=b;
			while(true){
				if(k==t)
					break;
				if(k<t){
					k=a*i;
					i++;
				}
				if(t<k){
					t=b*j;
					j++;
				}
			}
			x=k;
			//
			i=1;j=1;k=a;t=b;
			while(true){
				if(k==t)
					break;
				if(t<k){
					i++;
					if(a%i==0){
					k=a/i;
					}
				}
				if(k<t){
					j++;
					if(b%j==0){
					t=b/j;
					}
				}
			}
			y=k;
			System.out.println(y+" "+x);
			i=1;j=1;k=1;t=1;
		}
	}
}

Measured memory_bytes: 11000
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

use std::cmp::*;

fn main() {
    input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    }
    let rm = m * 6.;
    let rh = h * 30. + m * 0.5;
    let theta = (rm - rh) * 3.14159265359 / 180.;
    let t = a * a + b * b - 2. * a * b * theta.cos();
    println!("{}", t.sqrt());
}


Measured memory_bytes: 3044
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    int a, b, c, d, densya, basu;
    cin >> a >> b >> c >> d;
    if (a <= b)densya = a;
  	else densya=b;
    if (c <= d)basu = c;
  	else basu=d;
    cout << densya + basu << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

tree = [[] for i in range(n)]
for i in range(m):
    a, b = info[i]
    a -= 1
    b -= 1
    tree[a].append(b)

set_ = set([])
for i in range(n):
    for j in tree[i]:
        set_.add(j)

start = set([])
for i in range(n):
    if i not in set_:
        start.add(i)

memo = {}
dp = [0]*n

def solve(pos):
    if pos in memo:
        return memo[pos]
    if len(tree[pos]) == 0:
        memo[pos] = 0
        return memo[pos]

    tmp = 0
    for next_pos in tree[pos]:
        tmp = max(solve(next_pos) + 1, tmp)
    memo[pos] = tmp
    return memo[pos]

for i in range(n):
    solve(i)
ans = 0
for i in memo:
    ans = max(ans, memo[i])
print(ans)

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

int main(){
  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2;
  cin >> a1 >> a2;
  cin >> b1 >> b2;
  ll l1 = a1*t1+a2*t2, l2 = b1*t1+b2*t2;
  if(l1 == l2) {
    cout << "infinity" << endl;
    return 0;
  }
  if(l1 < l2) {
    swap(l1,l2); swap(a1,b1); swap(a2,b2);
  }
  if(a1 > b1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = (b1-a1)*t1/(l1-l2);
  if((b1-a1)*t1 % (l1-l2)) cout << ans*2 + 1 << endl;
  else cout << ans*2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;
const double PI = 3.14159265358979323846;

void bfs(vector<int> &visit, vector<vector<int>> &G, int s, int &count)
{

    visit[s] = 1;

    for (int v : G[s])
    {

        if (visit[v] == 0)
        {

            visit[v] = 1;
            count++;
            bfs(visit, G, v,count);

          
        }
        
    }
}

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

    vector<vector<int>> G(N, vector<int>(0));

    for (int i = 0; i < M; i++)
    {
        int A, B;

        cin >> A >> B;

        G[A - 1].push_back(B - 1);
        G[B - 1].push_back(A - 1);
    }
    vector<int> visit(N, 0);


    int count=0;

    int s_i = 0;

    int c=0;

    for(int i=0;i<N;i++){

        if(visit[i]==0){

            count++;
             bfs(visit, G, i,c);
        }
    
    }


    cout << count -1 << endl;

    return 0;
}

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

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

    int N;
    cin >> N;
    vector<ll> X(N), Y(N), P(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> P[i];
    }
    vector<vector<ll>> ver(1 << N, vector<ll>(N)), hor(1 << N, vector<ll>(N));
    for (int S = 0; S < 1 << N; S++) {
        for (int i = 0; i < N; i++) {
            ll v = abs(X[i]), h = abs(Y[i]);
            for (int j = 0; j < N; j++) {
                if (S >> j & 1) {
                    v = min(v, abs(X[i] - X[j]));
                    h = min(h, abs(Y[i] - Y[j]));
                }
            }
            ver[S][i] = v * P[i];
            hor[S][i] = h * P[i];
        }
    }
    vector<ll> ans(N+1, 1e18);
    for (int S = 0; S < 1 << N; S++) {
        int cnt = 0;
        int v = 0, h = 0;
        vector<int> vv, hh;
        for (int i = 0; i < N; i++) {
            if (S >> i & 1) {
                cnt++;
                vv.push_back(1 << i);
                hh.push_back(1 << i);
            }
        }
        for (int b = 0; b < 1 << cnt; b++) {
            int v = 0, h = 0;
            for (int i = 0; i < cnt; i++) {
                if (b >> i & 1) v += vv[i];
                else h += hh[i];
            }

            ll cost = 0;
            for (int i = 0; i < N; i++) {
                cost += min(ver[v][i], hor[h][i]);
            }
            ans[cnt] = min(ans[cnt], cost);
        }
    }
    for (int i = 0; i <= N; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 12884
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}


int lis[405][405];

int main(){
    int h,w;
    cin >> h>>w;
    char s[h][w];
    rep(i,405){
        rep(j,405){
            lis[i][j]=INF;
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
            if(s[i][j]=='.'){
                lis[w*i+j][w*i+j]=0;
            }
            if(i-1>-1&&s[i][j]=='.'&&s[i-1][j]=='.'){
                lis[w*i+j][w*(i-1)+j]=1;
                lis[w*(i-1)+j][w*i+j]=1;
            }
            if(i+1<h&&s[i][j]=='.'&&s[i+1][j]=='.'){
                lis[w*i+j][w*(i+1)+j]=1;
                lis[w*(i+1)+j][w*i+j]=1;
            }
            if(j-1>-1&&s[i][j]=='.'&&s[i][j-1]=='.'){
                lis[w*i+j][w*i+j-1]=1;
                lis[w*i+j-1][w*i+j]=1;
            }
            if(j+1<w&&s[i][j]=='.'&&s[i][j+1]=='.'){
                lis[w*i+j][w*i+j+1]=1;
                lis[w*i+j+1][w*i+j]=1;
            }
        }
    }
    rep(k,w*h){
        rep(i,w*h){
            rep(j,w*h){
                lis[i][j]=min(lis[i][j],lis[i][k]+lis[k][j]);
            }
        }
    }
    int ans=-INF;
    rep(i,h*w){
        rep(j,w*h){
            //cerr<<lis[i][j]<<' ';
            if(lis[i][j]!=INF){
                ans=max(ans,lis[i][j]);
            }
        }
        //cerr<<endl;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 896
from collections import defaultdict
import heapq

N,M = map(int,input().split())

l = defaultdict(list)
for i in range(N):
    A,B = map(int,input().split())
    l[A].append(-B)

h = []
ans = 0
for i in range(M):
    for B in l[i+1]:
        heapq.heappush(h,B)
    if len(h)!=0:
        ans += - heapq.heappop(h)
print(ans)


Measured memory_bytes: 77272
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String S = sc.next();
        // final int A = sc.nextInt();
        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int C = sc.nextInt();
        final int D = sc.nextInt();

        // System.out.println();
        int trainPrice = Math.min(A, B);
        int bussPrice = Math.min(C, D);
        System.out.println(trainPrice + bussPrice);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21844
N = int(input())

"""
N = 2
 No
N = 3
 1,2. 2,3. 3,1
N = 4
 No
N = 5
 No
N = 6
 1,2,4 1,3,6 4,5,6 2,3,5

個数がN(Nー1)でしょうと言うのは考察を諦めない力
全ての部分集合の長さって同じじゃね？って気付けるかどうか。。。
あとは６で具体的に構築できるかどうか勝負かな。
"""

def solve(k):
  print("Yes")
  print(k)
  G = []
  for i in range(1,k+1):
    G = calcG(i-1,G)
  for g in G:
    print(str(len(g)) + " " + " ".join(map(str,g)))
    
def calcG(i,G):
  st = i*(i-1) // 2 + 1
  en = i*(i+1) // 2
  #print(i,st,en)
  new = list(range(st,en+1))
  for j in range(len(G)):
    G[j].append(new[j])
  G.append(new)
  return G

for i in range(2,1000):
  if i*(i-1)//2 == N:
    solve(i)
    exit(0)

print("No")

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

int main() {
    long N, A, B;
    cin>>N>>A>>B;
    long h[N];
    long maxh = 0;
    for(int i=0;i<N;++i){
        cin>>h[i];
        if(maxh < h[i]) maxh = h[i];
    }
    long l = 0, r = maxh / B + 1;
    long m;
    long tmp;
    while(l<r){
        m = (l+r)/2;
        tmp = 0;
        for(int i=0;i<N;++i){
            if(h[i] - B*m<=0)continue;
            if((h[i]-B*m)%(A-B)==0){
                tmp += (h[i]-B*m)/(A-B);
            }
            else{
                tmp += (h[i]-B*m)/(A-B) + 1;
            }
        }
        if(tmp<=m){
            r = m;
        }
        else{
            l = m+1;
        }
    }
    cout<<l<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
int a,num[100];
cin >> a;
for(int z=0; z<a; z++){
cin >> num[z];
}
for(int z=a-1; z>=0; z--){
if(z!=a-1) cout << " ";
cout << num[z];
}
cout <<endl;
return 0;
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		long[][] indis = new long[n][n];
		long[][] dis = new long[n][n];
		
		long sum = 0;
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				indis[i][j] = sc.nextLong();
				if(i>j)sum+=indis[i][j];
			}
			dis[i] = indis[i].clone();
		}
		boolean[][] rip = new boolean[n][n];
		
		for(int k = 0; k < n; k++)
			for(int i = 0; i < n; i++)
				for(int j = 0; j < n; j++)
				{
					if(dis[i][j] > dis[i][k] + dis[k][j])
					{
						System.out.println(-1);
						return;
					}
					else if(!rip[i][j] && dis[i][j] == dis[i][k] + dis[k][j] && i != j && j != k && i != k && i > j)
					{
						sum-=dis[i][j];
						rip[i][j] = true;
					}
				}

		System.out.println(sum);
	}

}


Measured memory_bytes: 60656
#include <iostream>

using namespace std;

int n, k,h=0;

int main()
{
	char s[100005];
	cin >> n >> k;
	for (int i = 0; i <=n; i++) {
		s[i] = getchar();
	}

	for (int i = 2; i <=n; ++i)
		if (s[i] != s[i - 1])h++;
	if (n - h + 2 * k - 1 <= n - 1)h = n - h + 2 * k - 1;
	else h = n - 1;
	printf("%d",h);
}

Measured memory_bytes: 384
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define INTINF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;

int partition(int A[], int first, int last){
  int x = A[last];
  int i = first-1;
  for (size_t j = first; j < last; j++) {
    if (A[j]<=x) {
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1], A[last]);
  return i+1;

}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; std::cin >> n;
  int A[100000];
  for (size_t i = 0; i < n; i++) {
    std::cin >> A[i];
  }
  int q = partition(A, 0, n-1);
  for (size_t i = 0; i < n; i++) {
    if (0<i && i<n) {
      std::cout << " ";
    }

    if (i==q) {
      std::cout << "[" << A[i] << "]";
    }else{
      std::cout << A[i];
    }
  }
  std::cout  << '\n';

  return 0;
}



Measured memory_bytes: 3504
#include <stdio.h>
int main(){
  int a,b,alice,bob;
  scanf("%d %d",&a,&b); //入力

  if(a==b){  //引き分け
    printf("Draw\n");
    return 0;
  }

  if(a>b){
    if(b==1){
      printf("Bob\n");
    }
    else{
      printf("Alice\n");
    }
  }

  if(a<b){
    if(a==1){
      printf("Alice\n");
    }
    else{
      printf("Bob\n");
    }
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
const ll INF = 1e18;

vector<ll> dp, pre;

void go(ll i, const vector<ll> &v, ll mask, ll group, ll x){
	if(i == (ll)v.size()){
		dp[mask] = max(dp[mask], pre[group] + x);
		return;
	}
	go(i+1, v, mask, group, x);
	go(i+1, v, mask^(1<<v[i]), group^(1<<v[i]), x);
}


int main(){
	ll n; cin >> n;
	ll a[n][n];
	for(ll i = 0; i < n; ++i){
		for(ll j = 0; j < n; ++j){
			cin >> a[i][j];
		}
	}
	pre.resize(1<<n);
	for(ll mask = 0; mask < (1<<n); ++mask){
		ll t = mask, b = 0, t1 = 0;
		vector<ll> v;
		while(t){
			if(t&1){
				for(const ll &j : v){
					t1 += a[b][j];
				}
				v.push_back(b);
			}
			t >>= 1; ++b;
		}
		pre[mask] = t1;
	}
	dp.resize(1<<n, -INF);
	dp[0] = 0;
	for(ll mask = 0; mask < (1<<n); ++mask){
		vector<ll> v;
		for(ll i = 0; i < n; ++i){
			if(!(mask&(1<<i))) v.push_back(i);
		}
		go(0, v, mask, 0, dp[mask]);
	}
	cout << (ll)dp[(1<<n) - 1];
}

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

vector<vector<int>> tree;
vector<int> c;

void dfs(int u, int p, int& idx, vector<int>& ans) {
    idx++;
    ans[u] = c[idx];
    for (int v : tree[u]) {
        if (v == p) {
            continue;
        }
        dfs(v, u, idx, ans);
    }
}

int main() {
    int N;
    cin >> N;
    tree.resize(N);
    c.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    for (int i = 0; i < N; i++) {
        cin >> c[i];
    }

    sort(c.begin(), c.end(), greater<int>());
    vector<int> ans(N);
    int idx = -1;
    dfs(0, -1, idx, ans);

    ll sum = 0;
    for (int i = 1; i < N; i++) {
        sum += c[i];
    }
    cout << sum << endl;
    for (int a : ans) {
        cout << a << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> store;
    while (n > 0) {
        int num;
        cin >> num;
        store.push_back(num);
        n--;
    }

    sort(store.begin(), store.end());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += store[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int K,S,ans=0;
  cin >> K >> S;
  rep(i,K+1) rep(j,K+1) if(S-i-j>=0 && S-i-j<=K) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
def main(S):
  while len(S) > 0:
    if S[-1] == "m":
      if S[-5:] == "dream":
        S = S[:-5]
      else:
        print("NO")
        return 0
    elif S[-1] == "e":
      if S[-5:] == "erase":
        S = S[:-5]
      else:
        print("NO")
        return 0
    elif S[-1] == "r":
      if S[-6:] == "eraser":
        S = S[:-6]
      elif S[-7:] == "dreamer":
        S = S[:-7]
      else:
        print("NO")
        return 0
    else:
      print("NO")
      return 0
  else:
    print("YES")
    
main(input())

Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	std::vector<intt> c(9);
	for (auto& r : c) std::cin >> r;
	if(((c[0]-c[1] != c[3] -c[4])
		||(c[0] - c[1]!= c[6] - c[7])
		||(c[6] - c[7]!= c[3] - c[4]))
		||
		((c[1] - c[2] != c[4] - c[5])
			|| (c[1] - c[2] != c[7] - c[8])
			|| (c[7] - c[8] != c[4] - c[5]))
		||
		((c[0] - c[3] != c[1] - c[4])
			|| (c[2] - c[5] != c[0] - c[3])
			|| (c[2] - c[5] != c[1] - c[4]))
		||
		((c[3] - c[6] != c[4] - c[7])
			|| (c[3] - c[6] != c[5] - c[8])
			|| (c[5] - c[8] != c[4] - c[7]))){
		std::cout << "No" << std::endl;
		return 0;
	}
	std::cout << "Yes" << std::endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 16;

ll dp[1 << N], cost[1 << N], a[N + 1][N + 1];
int n;

vector<int> get_bits(int mask)
{
    vector<int> bits;

    for(int i = 0; (1 << i) <= mask; i++)
        if((1 << i) & mask)
            bits.push_back(i);

    return bits;
}

ll solve(int mask)
{
    // cout << "enter: " << mask << endl;

    ll &ans = dp[mask];

    if(ans != -1)
        return ans;

    ans = cost[mask];
    auto bits = get_bits(mask);
    int sz = bits.size();

    for(int submasks = 1; submasks < (1 << sz); submasks++)
    {
        int next = 0;
        for(int i = 0; i < sz; i++)
            if((1 << i) & submasks)
                next |= 1 << bits[i];

        ans = max(ans, cost[next] + solve(mask & ~next));
    }

    // cout << mask << " " << ans << endl;

    return ans;
}

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

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

    cin >> n;

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> a[i][j];

    for(int mask = 0; mask < (1 << n); mask++)
    {
        auto bits = get_bits(mask);
        int sz = bits.size();

        for(int i = 0; i < sz; i++)
            for(int j = i + 1; j < sz; j++)
                cost[mask] += a[bits[i]][bits[j]];
    }

    // cout << "here" << endl;
    // exit(0);

    cout << solve((1 << n) - 1) << endl;

    return 0;
}

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

using namespace std;

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

    int n,i;
    string str;
    cin>>n>>str;
    for(i=0;i<str.size();i++){
        if(str[i] + n > 'Z'){
            int c = n - 'Z' + str[i]-1;
            str[i] = 'A' + c;
        }
        else str[i] = str[i] + n;
    }
    cout<<str<<'\n';
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
ketasuu,content = [],[]
for _ in range(m):
    s,c = map(int,input().split())
    ketasuu.append(s-1)
    content.append(c)
ans = 10000-1
for i in range(0,10000):
    tmp =list(str(i)) 
    flag = []
    for j in range(m):
        try:
            if tmp[ketasuu[j]] == str(content[j]):
                flag.append(True)
            else:
                flag.append(False)
        except:
            pass
    if all(flag) and len(tmp)==n:
        ans = min(i,ans)
if ans == 10000-1:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 43500
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll T;
ll t[200010];

ll solve() {
    ll res = 0;
    t[n] = 1e18;
    for (int i = 0; i < n; i++) {
        if (t[i]+T<= t[i+1]) res += T;
        else res += t[i+1] - t[i];
    }
    return res;
}

void input() {
    cin >> n >> T;
    for (int i = 0; i < n; i++) cin >> t[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main() {
    i64 MOD = 1e9 + 7;
    i64 M,N;
    cin >> M >> N;
    i64 ans = 1;
    i64 now = M;
    while(N != 0){
        if(N & 1){
            ans = (ans * now) % MOD;
        }
        now = (now * now) % MOD;
        N >>= 1;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3104
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, N) {
        cin >> H[i];
    }

    vector<int> dp(N);
    for (int i = N - 2; i >= 0; --i) {
        if (H[i] >= H[i + 1]) {
            dp[i] = dp[i + 1] + 1;
        }
    }

    int ans = *max_element(all(dp));
    write(ans);
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	if (n < 3) {
		cout << "0" << endl;
		return 0;
	}
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l.at(i);
	}
	sort(l.begin(), l.end());
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (l.at(i) + l.at(j) > l.at(k)) {
					if (l.at(i) != l.at(j) && l.at(i) != l.at(k) && l.at(k) != l.at(j)) {
						cnt++;
					}
				}
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3588
a = int(input())
l = []

for i in range(a):
    t = int(input())
    l.append(t)
t =1
res = 0
for i in l[::-1]:
    if i >= t:
        res += i
    elif t - i == 1:
        t = 1
    else:
        l[0] = 1
    t = i
if l[0] ==0 :print(res)
else:print(-1)

Measured memory_bytes: 12588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, n-1) if(s[i] == s[i+1]) cnt++;
  cout << min(cnt + 2 * k, n - 1) <<endl;
}

Measured memory_bytes: 3756
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (a >= b && b >=c)    
        cout << c << " " << b << " " << a << endl;
    else if (a <= b && c <= a)    
        cout << c << " " << a << " " << b << endl;
    else if (b <= a && a <= c)    
        cout << b << " " << a << " " << c << endl;
    else if (b <= c && c <= a)    
        cout << b << " " << c << " " << a << endl;

 

}
 
 


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

int main()
{
	int d;
	cin>>d;
	if(d==25)cout<<"Christmas\n";
	else if(d==24)cout<<"Christmas Eve\n";
	else if(d==23)cout<<"Christmas Eve Eve\n";
	else if(d==22)cout<<"Christmas Eve Eve Eve\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    string s;
    cin >> s;
    int b, e;
    b = 1e9;
    e = -1;
    int n = s.size();
    rep(i, n)
    {
        if (s[i] == 'A' && i < b)
        {
            b = i;
        }
        else if (s[i] == 'Z' && i > e)
        {
            e = i;
        }
    }
    cout << e - b + 1 << endl;
    return 0;
}

Measured memory_bytes: 3724
N = int(input())
S = input()

Ans = [[0] * N for _ in range(4)]
Ans[0][0] = 1
Ans[0][1] = 1
Ans[1][0] = 1
Ans[1][1] = 2
Ans[2][0] = 2
Ans[2][1] = 1
Ans[3][0] = 2
Ans[3][1] = 2

def isok(a):
    for i, s in enumerate(S):
        if i + 2 < N:
            if s == 'o':
                if a[i + 1] == 1:
                    a[i + 2] = a[i]
                else:
                    a[i + 2] = 3 - a[i]
            else:
                if a[i + 1] == 1:
                    a[i + 2] = 3 - a[i]
                else:
                    a[i + 2] = a[i]
        else:
            if s == 'o':
                if a[(i + 1) % N] == 1:
                    if a[(i + 2) % N] != a[i]:
                        return False
                else:
                    if a[(i + 2) % N] + a[i] != 3:
                        return False
            else:
                if a[(i + 1) % N] == 1:
                    if a[(i + 2) % N] + a[i] != 3:
                        return False
                else:
                    if a[(i + 2) % N] != a[i]:
                        return False
    return True

flag = True
num = -1
for i in range(4):
    if isok(Ans[i]):
        num = i
        flag = False
        break
if flag:
    print(-1)
else:
    for a in Ans[num][1:]:
        if a == 1:
            print('S', end='')
        else:
            print('W',end='')
    if Ans[num][0] == 1:
        print('S')
    else:
        print('W')

Measured memory_bytes: 57820
S = input()

M = [str(m).zfill(2) for m in range(1,13)]

if S[:2] not in M:
  if S[2:] not in M:
    print('NA')
  else:
    print('YYMM')
else:
  if S[2:] in M:
    print('AMBIGUOUS')
  else:
    print('MMYY')

Measured memory_bytes: 2940
N,M = map(int, input().split())

wa_counter = [ 0 for i in range(N)]
ac_flag = [ 0 for i in range(N)]
penalty_sum = 0

for i in range(M):
  P, outcome = map(str, input().split())
  P = int(P) -1
  if ac_flag[P] == 0 and outcome == "AC":
    ac_flag[P] = 1
    penalty_sum += wa_counter[P]
  elif ac_flag[P] == 0 and outcome == "WA":
    wa_counter[P] += 1
  else:
    pass

print(sum(ac_flag), penalty_sum) 

Measured memory_bytes: 4760
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

int main(void) {
	int x, y;
	cin >> x >> y;
	if (x+y<24)cout << x+y << endl;
	else cout << x+y-24 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string a,b;
  while(cin>>a>>b){
    int c=0,d=0;
    if(a.size()==1&&a[0]=='0')break;
    r(i,4){
      if(a[i]==b[i])c++;
      else r(j,4)if(a[i]==b[j])d++;
    }
    cout<<c<<' '<<d<<endl;
  }
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> b(N);
    a.at(0) = 1;
    b.at(N - 1) = 1;
    for(int i = 0;i < N - 1;i++) {
        a.at(i + 1) = a.at(i) + 20001;
    }
    for(int i = N - 1;i >= 1;i--) {
        b.at(i - 1) = b.at(i) + 20001;
    }
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        A--;
        vec.at(i) = A;
    }
    for(int i = 0;i < N;i++) {
        a.at(vec.at(i)) += i;
    }
    for(int i = 0;i < N;i++) {
        cout << a.at(i) << " ";
    }
    cout << endl;
    for(int i = 0;i < N;i++) {
        cout << b.at(i) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int n,min,max;
    int a[105];
    scanf("%d",&n);
    for(int count=1;count<=n;count++){
        scanf("%d",&a[count]);
    }
    min=1000000050;
    max=0;

    for(int count2=1;count2<=n;count2++){
        if(a[count2]<=min){min=a[count2];}
        if(a[count2]>=max){max=a[count2];}   
    }
    printf("%d\n",abs(max-min));
}


Measured memory_bytes: 128
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
length=len(str(n))

ans=0
for i in range(1,10):
    if n<i:
        break
    s=0
    for j in range(1,length+1):
        if j<=1:
            s+=1
        elif j<length:
            s+=(10**(j-2))
        else:
            if not(length==6 and i>=2):
                for m in range(n,10**(length-1),-1):
                    if str(m)[0]==str(m)[-1]==str(i):
                        s+=1
    ans+=s*s
for i1 in range(1,10):
    for i2 in range(1,10):
        if i1==i2:
            break;
        s1=0
        s2=0
        for j in range(2,length+1):
            if j<length:
                s1+=10**(j-2)
                s2+=10**(j-2)
            else:
                if not(length==6 and i1>=2 and i2>=2):
                    for m in range(n,10**(length-1),-1):
                        if str(m)[0]==str(i1) and str(m)[-1]==str(i2):
                            s1+=1
                        elif str(m)[0]==str(i2) and str(m)[-1]==str(i1):
                            s2+=1
        ans+=s1*s2*2
print(ans)

Measured memory_bytes: 3188
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B
 */
#include <iostream>
#include <vector>

using namespace std;

bool
binarysearch(const vector<int> &a, const int key)
{
    int left = 0;
    int right = a.size();
    while (left < right) {
        int mid = (left + right) / 2;
        if (a.at(mid) == key) { 
            return true; 
        } else if (key < a.at(mid)) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return false;
}

int
main()
{
    int n;
    cin >> n; cin.ignore();

    vector<int> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i]; cin.ignore();
    }

    int q;
    cin >> q; cin.ignore();

    vector<int> T(q);
    for (int i = 0; i < q; i++) {
        cin >> T[i]; cin.ignore();
    }

    int count = 0;
    for (int it : T) {
        if (binarysearch(S, it)) { count++; }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1000000000


struct Node{
	int left,right,file_id;
	Node* prev;
	Node* next;
};

class List{
public:
	List(){
		motherNode = new Node();
		motherNode->file_id = -1;
		motherNode->prev = new Node();
		motherNode->next = motherNode->prev;

		motherNode->next->left = 0;
		motherNode->next->right = NUM;
		motherNode->next->file_id = -1;

		motherNode->next->next = motherNode;
		motherNode->next->prev = motherNode;

	};
	void writeFile(int id,int size){

		int rest = size,node_size;

		Node* tmpNode = motherNode->next;

		while(rest > 0 && tmpNode != motherNode){
			if(tmpNode->file_id == -1){
				node_size = tmpNode->right-tmpNode->left+1;
				if(node_size > rest){

					Node* tmp_next = tmpNode->next;
					tmpNode->next = new Node;

					tmpNode->next->right = tmpNode->right;
					tmpNode->next->left = tmpNode->left+rest;
					tmpNode->next->file_id = -1;
					tmpNode->next->next = tmp_next;
					tmpNode->next->prev = tmpNode;

					tmpNode->right = tmpNode->left+rest-1;
					tmpNode->file_id = id;

					break;
				}else{
					tmpNode->file_id = id;
					rest -= node_size;
				}
			}
			tmpNode = tmpNode->next;
		}
	};

	void delete_File(int id){
		Node* tmpNode = motherNode->next;
		if(tmpNode->file_id == id){
			tmpNode->file_id = -1;
		}
		tmpNode = tmpNode->next;
		while(tmpNode != motherNode){
			if(tmpNode->file_id == id){
				tmpNode->file_id = -1;
			}
			tmpNode = tmpNode->next;
		}
	};

	int search_id(int loc){
		Node* tmpNode = motherNode->next;
		if(tmpNode->left <= loc && tmpNode->right >= loc){
			return tmpNode->file_id;
		}
		tmpNode = tmpNode->next;
		while(tmpNode != motherNode){
			if(tmpNode->left <= loc && tmpNode->right >= loc){
				return tmpNode->file_id;
			}
			tmpNode = tmpNode->next;
		}
		return -1;
	}

private:
	Node* motherNode;
};

int N;

void func(){

	List list;

	char command[2];
	int id,size,loc;

	for(int loop = 0; loop < N; loop++){

		scanf("%s",command);

		switch(command[0]){
		case 'W':
			scanf("%d %d",&id,&size);
			list.writeFile(id,size);
			break;
		case 'D':
			scanf("%d",&id);
			list.delete_File(id);
			break;
		case 'R':
			scanf("%d",&loc);
			printf("%d\n",list.search_id(loc));
			break;
		}
	}

	printf("\n");
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3144
def solve():
    a, b, c = map(int, input().split())
    if a == b + c:
        ans = "Yes"
    elif b == a + c:
        ans = "Yes"
    elif c == a + b:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 2940