akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

bool kw[101][101];
bool sp[101];

signed main() {
	int n, m, p, k, l;
	while (cin >> n && n) {
		rep(i, 0, n) rep(j, 0, n) {
			kw[i][j] = false;
		}
		rep(i, 0, n) sp[i] = true;
		rep(i, 0, n) {
			cin >> m;
			rep(j, 0, m) {
				cin >> p;
				kw[i][p - 1] = true;
			}
		}
		cin >> k;
		vi lost(k);
		rep(i, 0, k) {
			cin >> l;
			lost[i] = l - 1;
		}
		vi d;
		rep(i, 0, n) {
			rep(j, 0, k) {
				if (kw[i][lost[j]] == false) break;
				if (j == k - 1) d.push_back(i);
			}
		}
		int ans = -1;
		if (d.size() == 1) ans = d[0] + 1;
		cout << ans << endl;
	}
}

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

typedef long long ll;

int main()
{
    int n,m;
    int i,j;
    cin >> n;
    vector<int> d(n);
    for(i = 0;i < n;++i){
        cin >> d.at(i);
    }
    ll ans = 0;
    for(i = 0;i < n;++i){
        for(j = 0;j < n;++j){
            ans += d.at(i)*d.at(j);
        }
    }
    for(i = 0;i < n;++i){
        ans -= d.at(i)*d.at(i);
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include<time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

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

int dfs(vvi &s,int y,int x,vvi &visited,int color){
	visited[y][x]=1;
	int ret=1;
	REP(d,6){
		int yy=y+dy[d];
		int xx=x+dx[d];
		if(yy>=0&&yy<s.size()&&xx>=0&&xx<=yy&&!visited[yy][xx]){
			if(s[yy][xx]==color){
				int num=dfs(s,yy,xx,visited,color);
				if(num==-1){
					return -1;
				}else{
					ret+=num;
				}
			}else if(s[yy][xx]==0){
				return -1;
			}
		}
	}
	return ret;
}

int main(){
	int n,c;
	while(cin>>n>>c,n|c){
		vvi s(n,vi(n));
		REP(i,n){
			REP(j,i+1){
				cin>>s[i][j];
			}
		}
		int ans=INT_MIN;
		REP(i,n){
			REP(j,i+1){
				if(s[i][j]==0){
					int num=0;
					vvi visited(n,vi(n));
					visited[i][j]=1;
					REP(d,6){
						int y=i+dy[d];
						int x=j+dx[d];
						if(y>=0&&y<s.size()&&x>=0&&x<=y&&!visited[y][x]){
							if(s[y][x]!=c&&s[y][x]){
								int d=dfs(s,y,x,visited,s[y][x]);
								if(d!=-1){
									num+=d;
								}
							}
						}
					}
					vvi ns(s);
					ns[i][j]=c;
					int d=dfs(ns,i,j,visited,c);
					if(d!=-1){
						num-=d;
					}
					ans=max(ans,num);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1220
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,d,a,now,ans,tmp;
struct M{
	int x,h,l;
}m[200002];
bool cmp(const M &A,const M &B)
{
	return A.x<B.x;
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>d>>a;
	d<<=1;
	for(int i=1;i<=n;++i)
	{
		cin>>m[i].x>>m[i].h;
	}
	sort(m+1,m+1+n,cmp);
	for(int i=1;i<=n;++i)
	{
		while(m[now].x<=m[i].x+d&&now<=n)
		{
			++now;
		}
		tmp=max((m[i].h-m[i].l*a)/a+((m[i].h-m[i].l*a)%a>0),i-i);
		ans+=tmp;
		m[now].l-=tmp;
		m[i].l+=tmp;
		m[i+1].l+=m[i].l;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

vector<int> v(5, 0);
ll dfs(int i, int use, ll total) {
  if (use == 3)
    return total;
  if (i == 5 && use != 3)
    return 0;
  ll s1 = dfs(i + 1, use + 1, total * v[i]);
  ll s2 = dfs(i + 1, use, total);
  return s1 + s2;
}

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

  int n;
  cin >> n;
  ll ans = 0;

  rep(i, 0, n) {
    string s;
    cin >> s;
    switch (s[0]) {
    case 'M':
      v[0]++;
      break;
    case 'A':
      v[1]++;
      break;
    case 'R':
      v[2]++;
      break;
    case 'C':
      v[3]++;
      break;
    case 'H':
      v[4]++;
      break;
    default:
      break;
    }
  }

  cout << dfs(0, 0, 1) << endl;
}


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

using namespace std;

using ll = long long;

int main(){
	int n, a, b;

	cin >> n;
	cin >> a;
	cin >> b;
	
	int ret;

	if (a * n <= b) {
		ret = a * n;
	} else {
		ret = b;
	}

	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y)
{
    if (x == 0)
        return y;
    return gcd(y % x, x);
}

int main()
{
    long long x, y;
    cin >> x >> y;
    cout << x * y / gcd(x, y) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
typedef long long ll;
void fmax(ll&a,ll b){
	a<b?a=b:0;
}
int a[100010],b[100010],n;
ll get(int x){
	int i;
	ll s=0;
	for(i=1;i<=n;i++){
		if((x&a[i])==a[i])s+=b[i];
	}
	return s;
}
int main(){
	int k,i,x;
	ll s;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d%d",a+i,b+i);
	s=get(k);
	x=k;
	for(i=0;i<30;i++){
		if(k>>i&1)fmax(s,get(x&~(1<<i)));
		x|=1<<i;
	}
	printf("%lld",s);
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    int n;cin >> n;
    int e_set[7]={1,2,4,8,16,32,64};
    for(int i=6;i>=0;i--){
        if(n>=e_set[i]) {
            p(e_set[i])
            return 0;
        }
    }
}

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

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	
	string S;
	cin >> S;
	
	vector<int> nums;
	
	int now = 1;
	int cnt = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == (char)('0' + now)) {
			cnt++;
		} else {
			now = 1 - now;
			nums.push_back(cnt);
			cnt = 1;
		}
	}
	nums.push_back(cnt);	// 最後の要素
	
	
	int res = 0;
	int k_now = 0;
	int tmp = 0;
	/* start位置 */
	for (int i = 0; i < nums.size(); i+=2) {	// 1始まりでループ
		/* 計測 */
		for (int j = i; j < nums.size(); j++) {
			if (j % 2 == 0) {		// 1の連続数
				tmp += nums[j];
			} else {		// 0の連続数
				if (k_now >= K)
					break;
				k_now++;
				tmp += nums[j];
			}
		}
		res = max(res, tmp);
		tmp = 0;
		k_now = 0;
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1020
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
dic_s = defaultdict(str)
dic_t = defaultdict(str)
s = input()
t = input()
# sets = sorted(list(set(s)))
# sett

for i in range(len(s)):
    if dic_s[s[i]] or dic_t[t[i]]:
        #print(s[i],t[i],dic[s[i]], dic[t[i]])
        if dic_s[s[i]] == t[i] and dic_t[t[i]] == s[i]:
            pass
        else:
            print('No')
            exit()
    else:
        dic_s[s[i]] = t[i]
        dic_t[t[i]] = s[i]
print("Yes")


Measured memory_bytes: 4144
#include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;

int main() {
int N,M;
  cin >> N>>M;
  vec L(M),R(M);
  for(int i=0;i<M;i++) cin >> L[i] >> R[i];
 sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  intk ans ;
  if(R[0] - L[M-1] <0) ans =0;
  else ans = R[0]- L[M-1]+1;
  cout <<ans <<endl;
}
  


Measured memory_bytes: 1024
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    scan(N);

    int ans;

    foreach (i ; 1 .. N + 1) {
        if (i % 2 && countDiv(i) == 8) ans++;
    }

    writeln(ans);
}

int countDiv(int x) {
    int[] divs;

    for (int i = 1; i <= x; i++) {
        if (x % i == 0) divs ~= i;
    }

    return divs.length.to!int;
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();
		System.out.println((x >= a && x <= a+b) ? "YES" : "NO");
		sc.close();
	}
}

Measured memory_bytes: 21844
n = int(raw_input())
inputs = [int(i) for i in raw_input().split()]

f = [0] * n

f[0] = 0
f[1] = abs(inputs[0]-inputs[1])
for i in range(2,n):
	f[i] = min(f[i-1] + abs(inputs[i]-inputs[i-1]), f[i-2] + abs(inputs[i]-inputs[i-2]))

# print f
print f[-1]

Measured memory_bytes: 44336
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    xor = 0
    for i in arr:
        xor = xor^i

    ans = []
    for i in arr:
        ans.append(xor^i)

    for i in ans:
        print(i,end = ' ')


main()


Measured memory_bytes: 102380
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
ll arr[410], dp[410][410], sum[410][410]; /// pos, len
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> arr[i];
    for(int i = 1; i <= n; i++)
    {
        ll cur = 0;
        for(int j = i; j <= n; j++)
        {
            cur += arr[j];
            sum[i][j] = cur;
        }
    }
    for(int i = 1; i < 410; i++)
        for(int j = 2; j < 410; j++)
            dp[i][j] = (ll)1e16;
    for(int len = 2; len <= n; len++)
    {
        for(int i = 1; i + len - 1 <= n; i++)
        {
            for(int j = i + 1; j <= i + len - 1; j++)
            {
                dp[i][len] = min(dp[i][len], dp[i][j - i] + dp[j][(i + len - 1) - j + 1] + sum[i][i + len - 1]);
            }
        }
    }
    cout << dp[1][n] << "\n";
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if((C-1)/B<=(A-1)/D){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3624
a1 = [str(i) for i in input().split()]
a2 = [str(i) for i in input().split()]
a3 = [str(i) for i in input().split()]
a = [a1,a2,a3]
new_a = []
import itertools
a = list(itertools.chain.from_iterable(a))
n = int(input())
l = [str(input()) for _ in range(n)]
l = list(set(l))
for i in a:
    if i in l:
        item_mod = i.replace(i,'o')
        new_a.append(item_mod)
    else:
        new_a.append(i)
import numpy
a = numpy.array(new_a).reshape(3,3)
yoko1 = []
yoko2 = []
yoko3 = []
tate1 = []
tate2 = []
tate3 = []
for i in range(3):
    yoko1.append(a[0][i])
    yoko2.append(a[1][i])
    yoko3.append(a[2][i])
    tate1.append(a[i][0])
    tate2.append(a[i][1])
    tate3.append(a[i][2])
naname1 = [a[0][0],a[1][1],a[2][2]]
naname2 = [a[0][2],a[1][1],a[2][0]]
x = ['o','o','o']
if x == yoko1:
    print('Yes')

elif x == yoko2:
    print('Yes')

elif x == yoko3:
    print('Yes')

elif x == tate1:
    print('Yes')

elif x == tate2:
    print('Yes')

elif x == tate3:
    print('Yes')

elif x == naname1:
    print('Yes')

elif x == naname2:
    print('Yes')

else:
    print('No')

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

int main()
{
    int n;
    cin >> n;
    for(int i=0; i<3; i++){
        if(n%10 == 7) {cout << "Yes" << endl; return 0;}
        n /= 10;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3136
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        int w = scan.nextInt();
        System.out.println(solve(s, w));
    }
    public static String solve(String s, int w) {
        char[] data = s.toCharArray();
        int length = data.length;
        int count = length / w + (length % w == 0 ? 0 : 1);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < count; i++) {
            sb.append(data[i * w]);
        }
        return sb.toString();
    }
}


Measured memory_bytes: 25812
import sys
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    count =0
    for i in range(1,N+1):
        if int(math.log10(i)) %2 ==0:
            count +=1
    print(count)



if __name__ == "__main__":
    main()


Measured memory_bytes: 66792
#include <stdio.h>

int main(void){

int a,b,c,x,n;

x=0;

scanf("%d %d %d",&a,&b,&c);

for(n=a;n<=b;n++){

if(c%n==0){

x = x+1;

};

};

printf("%d\n",x);

return 0;

};

Measured memory_bytes: 596
import math
import numpy as np
from fractions import gcd
import collections

C = [list(map(int,input().split())) for l in range(3)]

C = np.array(C)

cross1 = C[0][0] + C[1][1] + C[2][2]
cross2 = C[0][2] + C[1][1] + C[2][0]
if(cross1 == cross2 and np.sum(C)/6 == cross1/2):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 13520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main()
{
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int ans = x*min(k, n) + y*max(n-k, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;


ll mod=1e9+7;

int main()
{
   
   
   ll s;
   cin>>s;
   ll dp[s+10];
   dp[0]=1;
   dp[1]=0;
   dp[2]=0;
   for(ll i=3;i<=s;i++)
   {
       ll sum=0;
       for(ll j=0;j<i-2;j++) sum=(sum+dp[j])%mod;
       dp[i]=sum;
   }
   cout<<dp[s]<<nn;





}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a.at(i);
    }
    
    int min=a.at(0);
    int diff=a.at(1)-min;
    for(int i=1;i<n;i++){
        if(a.at(i)-min>diff){
            diff=a.at(i)-min;
        }
        if(a.at(i)<min) min=a.at(i);
    }
    cout<<diff<<endl;
    return 0;
}

 


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
int main()
{
    int m,n,i,j,c;
    scanf("%d%d",&m,&n);
    getchar();
    char s[m][n];
    int p[m][n];
    for(i=0; i<m; i++)
    {
        for(j=0; j<n; j++)
        {
            scanf("%c",&s[i][j]);
            if(s[i][j]=='.')
                p[i][j]=1;
            if(s[i][j]=='#')
                p[i][j]=0;
        }
        getchar();
    }
    for(i=0; i<m; i++)
    {
        for(j=0; j<n; j++)
        {
            if(j<=n-2&&s[i][j]=='#'&&s[i][j+1]=='#')
            {
                p[i][j]=1;
                p[i][j+1]=1;
            }
            if(i<=m-2&&s[i][j]=='#'&&s[i+1][j]=='#')
            {
                p[i+1][j]=1;
                p[i][j]=1;
            }
        }
    }
    for(i=0,c=1; i<m; i++)
    {
        for(j=0; j<n; j++)
        {
            if(p[i][j]==0)
            {
                c=0;
                break;
            }
        }
    }
    if(c)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

int main() {
	int n,l;
	cin>>n>>l;
	
	int sum=(n*(n-1))/2 + l*n,maxn=l;
	for(int i=1;i<n;i++)
		if(abs(0-maxn)>abs(0-l-i))
			maxn=l+i;
	
	cout<<sum-maxn<<'\n';
}

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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var result = 1;

            for (int i = 0; i + 1 < n; i++)
            {
                if (s[i] != s[i + 1])
                {
                    result++;
                }
            }

            Console.WriteLine(result);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13140
d, g = gets.split.map(&:to_i)
g /= 100
ps = []
cs = []

d.times do
  p, c = gets.split.map(&:to_i)
  ps << p
  cs << (c / 100)
end

calc = lambda { |bs|
  score = 0
  count = 0
  bs.each_with_index do |b, i|
    if b
      score += cs[i] + (i + 1) * ps[i]
      count += ps[i]
    end
  end

  [score, count]
}

min = ps.reduce(:+)

[true, false].repeated_permutation(d) do |bs|
  score, count = calc.call(bs)

  (d-1).downto(0) do |i|
    if score < g && bs[i] == false
      inc = [ps[i], (g - score + i) / (i + 1)].min
      count += inc
      score += inc * (i + 1)
    end
  end

  min = [count, min].min
end

p min


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.EducationalDP
{
    class M
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            int[] array = ReadInts();
            long[,] dp = new long[100, k+1];
            long mask = 1000000000 + 7;
            for (int i = 0; i <= Math.Min(array[0], k); i++) dp[0, i] = 1;
            for (int i = 1; i < n; i++)
            {
                long[] sums = new long[k+1];
                sums[0] = dp[i - 1, 0];
                for (int j = 1; j <= k; j++)
                {
                    sums[j] = sums[j - 1] + dp[i - 1, j];
                }
                for (int j = 0; j <= k; j++)
                {
                    int index = j - array[i] - 1;
                    dp[i, j] = sums[j];
                    if (index >= 0) dp[i, j] -= sums[index];
                    dp[i, j] %= mask;
                }
            }
            /*for (int i = 0; i < n; i++)
            {
                for (int j = 0; j <= k; j++)
                {
                    Console.Write(dp[i, j] + " ");
                }
                Console.WriteLine();
            }*/
            Console.WriteLine(dp[n - 1, k]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 113292
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000000
#define max 10000

int main(){
  unsigned short *A,*B;

  int C[max+1];
  int n,i,j;
  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0;i<=max;i++) C[i]=0;

  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=max;i++) C[i] = C[i]+C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 9596
using System;

namespace AtCoder {
    class Program {
        static void Main(string[] args) {
            var inputs = Console.ReadLine().Split(' ');
            bool[] flags = new bool[4] { false, false, false,false};

            foreach(var s in inputs)
            {
                switch (s)
                {
                    case "1":
                        if (!flags[0])
                        {
                            flags[0] = true;
                        } else
                        {
                            Console.WriteLine(No);
                            return;
                        }
                        break;
                    case "9":
                        if (!flags[1])
                        {
                            flags[1] = true;
                        } else
                        {
                            Console.WriteLine(No);
                            return;
                        }
                        break;
                    case "7":
                        if (!flags[2])
                        {
                            flags[2] = true;
                        } else
                        {
                            Console.WriteLine(No);
                            return;
                        }
                        break;
                    case "4":
                        if (!flags[3])
                        {
                            flags[3] = true;
                        } else
                        {
                            Console.WriteLine(No);
                            return;
                        }
                        break;
                    default:
                        Console.WriteLine(No);
                        return;
                        
                }

            }
            Console.WriteLine(Yes);
            return;
        }

        static string No = "NO";
        static string Yes = "YES";

    }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {
    private static final int MIN = -1000001;
    private static final int MAX = 1000001;
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int d = scn.nextInt(), n = MAX, x = MIN;
        long s = 0;
        for(int i = 0; i < d; i++) {
            int a = scn.nextInt();
            if(a < n) {
                n = a;
            }
            if(a > x) {
                x = a;
            }
            s += a;
        }
        System.out.println(n + " " + x + " " + s);
    }
}

Measured memory_bytes: 31760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<ll, ill>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

ll dp[40][40];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<int> x(n);
    rep(i, n) {
        string s;
        cin >> s;
        int index = 0;
        while (index<s.size() && s[index]!='.') {
            a[i] *= 10;
            a[i] += s[index] - '0';
            index++;
            
        }
        index++;
        x[i] = max((int)s.size() - index, 0);
        while (index<s.size()) {
            a[i] *= 10;
            a[i]+= s[index] - '0';
            index++;
        }
        //debug(x[i]);
    }
    ll ans = 0;
    rep(i, n) {
        ll f[2] = {2, 5};
        ll res[2] = {0, 0};
        rep(j, 2) {
            ll v = a[i];
            ll z = 0;
            while (v%f[j]==0) {
                v /= f[j];
                z++;
            }
            res[j] = min(z, 20LL);
        }
        int thx = x[i]-res[0]+20;
        int thy = x[i]-res[1]+20;
        for (int xx=thx; xx<=40; xx++) {
            for (int yy=thy; yy<=40; yy++) {
                ans += dp[xx][yy];
            }
        }
        dp[res[0]-x[i]+20][res[1]-x[i]+20]++;
    }
    
    cout << ans << endl;
    return 0;
}


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

int main() {
	int N, X, Y, aux;
	std::cin >> N >> X >> Y;

	std::vector<int> v(N);
	for (int i = 1; i <= N; ++i) {
		for (int j = i + 1; j <= N; ++j) {
			int aux = std::min(j - i, std::abs(i - X) + 1 + std::abs(Y - j));
			++v[aux];
		}
	}
	for (int i = 1; i < N; ++i) std::cout << v[i] << '\n';
	
return 0;
}

Measured memory_bytes: 256
//Keep Working Hard
  // I__Like__Food  
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int mod = 1e9 + 7;
  const int N = 200005;
  const int INF = 1e16;
  const double PI = acos(-1);


int32_t main()
{
       

    IOS




    int x;
    cin >> x;

    int a =  (x/500)*1000 ;

    x%=500;

    int b = x/5 * 5;

    cout << a + b;


  return 0;
} 

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

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)        memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;


int main()
{
    fastio;
    int n;
    cin>>n;
    ll a[n],ans=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        
    }
    sort(a,a+n,greater<int>());
    ans+=a[0];
    int x;
    if(n%2==0)
    for(int i=0,j=1; i<(n-1)/2; i++)
    {
        ans+=a[j]*2;j++;
    }

    else
    {
        for(int i=0,j=1; i<(n-2)/2; i++,j++)
        {
            ans+=a[j]*2;
            x=j;
        } 
        ans+=a[x+1];
    }
    
    cout<<ans<<nl;
}

Measured memory_bytes: 5220
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int N, K, ans = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        ans += min(2 * x, 2 * abs(x - K));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct data{
  int p[100];
  int f;
  char w[31];
};

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

int main(void){
  int i,j,n,t;
  char s[31];
  struct data d[100]={0},tmp;
  n=0;
  while(1){
    if(scanf("%s %d",s,&t)==EOF)
      break;
    for(i=0;i<n;i++){
      if(strcmp(d[i].w,s)==0){
	d[i].p[d[i].f]=t;
	break;
      }
    }
    if(i==n){
      sprintf(d[i].w,"%s",s);
      d[i].p[0]=t;
      n++;
    }
    d[i].f++;
  }
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(strcmp(d[j-1].w,d[j].w)>0){
	tmp=d[j-1];
	d[j-1]=d[j];
	d[j]=tmp;
      }
    }
  }
  for(i=0;i<n;i++)
    qsort(d[i].p,d[i].f,sizeof(int),cmp);
  for(i=0;i<n;i++){
    printf("%s\n",d[i].w);
    for(j=0;j<d[i].f-1;j++)
      printf("%d ",d[i].p[j]);
    printf("%d\n",d[i].p[j]);
  }
  return 0;
}

Measured memory_bytes: 676
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void msort(int *a,int n,int *tmp){
  if(n<=1) return;
  int m=n/2;
  msort(a,m,tmp);
  msort(a+m,n-m,tmp);
  int i=0;
  int j=m;
  int k=0;
  while(i<m && j<n){
    if(a[i]<=a[j]){
      tmp[k++]=a[i++];
    } else {
      tmp[k++]=a[j++];
    }
  }
  while(i<m) tmp[k++]=a[i++];
  while(j<n) tmp[k++]=a[j++];
  for(i=0;i<n;i++) a[i]=tmp[i];
  return;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int max=a[0];
  for(i=1;i<n;i++) max=MAX(a[i],max);
  i=0;
  if(a[i]==max) i++;
  double min=ABS((double)max/2-a[i]);
  int index=a[i];
  for(i=i+1;i<n;i++){
    if(a[i]==max) continue;
    if(ABS((double)max/2-a[i])<min){
      min=ABS((double)max/2-a[i]);
      index=a[i];;
    }
  }
  printf("%d %d\n",max,index);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 512
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897L
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"No\n"; return 0;}
#define yup {cout<<"Yes\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

bool ispalin(string a) {
    string t = a; reverse(ALL(t));
    return t==a;
}
int main() {


    get(n);
    double l = n; 
    l /= 3;
    printf("%.10f\n", l*l*l);


    return 0;  
}   


Measured memory_bytes: 256
def insetSort(lst,n):
    count = 0
    for i in range(0,n):
        min = i
        for j in range(i,n):
            if lst[j] < lst[min]: min = j
        if lst[i] != lst[min]: count += 1
        lst[i],lst[min] = lst[min],lst[i]

    return lst,count

n = int(input())
lst = [int(i) for i in input().split()]
lst = insetSort(lst,n)

print(*lst[0])
print(lst[1])


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int long long
const int N = 1e5+7;

int n, ans;

int L[N];
int R[N];

struct compL
{
	bool operator()(int a, int b)
	{
		if(R[a]==R[b])
			return a<b;

		return R[a]<R[b];
	}
};

struct compR
{
	bool operator()(int a, int b)
	{
		if(L[a]==L[b])
			return a<b;

		return L[a]>L[b];
	}
};

set<int, compL> sL;
set<int, compR> sR;

int dist(int curr, int ind)
{
	if(L[ind]<=curr && curr<=R[ind])
		return 0;

	return min(abs(curr-L[ind]), abs(curr-R[ind]));
}

int move(int curr, int ind)
{
	if(L[ind]<=curr && curr<=R[ind])
		return curr;

	if(abs(curr-L[ind])<abs(curr-R[ind]))
		return L[ind];
	else
		return R[ind];
}

int solve(int x)
{
	for(int i = 1; i <= n; ++i)
	{
		sL.insert(i);
		sR.insert(i);
	}

	int curr = 0, sum = 0;

	for(int i = 1; i <= n; ++i)
	{
		int ind = -1;

		if(i%2==x)
		{
			ind = *sL.begin();
		}
		else
		{
			ind = *sR.begin();
		}

		sL.erase(ind);
		sR.erase(ind);
		sum += dist(curr, ind);
		curr = move(curr, ind);
	}

	sum += abs(curr);
	return sum;
}

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

	cin >> n;

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

	ans = max(ans, solve(0));
	ans = max(ans, solve(1));

	cout << ans << endl;
}

Measured memory_bytes: 13184
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include <cstdlib>
using namespace std;
int main() {
	long long n;
	cin >> n;
	long long total = 0;
	long long counter = 0;

	long long total2 = 0;
	long long counter2 = 0;

	long long a;

	for (int i = 0; i < n; i++) {
		cin >> a;
		total += a;
		total2 += a;
		if (i % 2 == 0) {
			if (total <= 0) {
				counter += abs(total) + 1;
				total = 1;
			}
		}
		else {
			if (total >= 0) {
				counter += abs(total) + 1;
				total = -1;
			}
		}

		if (i % 2 == 0) {
			if (total2 >= 0) {
				counter2 += abs(total2) + 1;
				total2 = -1;
			}
		}
		else {
			if (total2 <= 0) {
				counter2 += abs(total2) + 1;
				total2 = 1;
			}
		}
	}

	if (counter < counter2)	cout << counter << endl;
	else cout << counter2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int w,h,sx,sy,gx,gy,ans,HM;
int mas[22][22];
bool used[22][22];
typedef pair<int,int> P;
void bfs(int cnt,P p);
P move(P,int);
int main(){
  while(1){
    cin >> w >> h;
    if(w==0&&h==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> mas[i][j];
	if(mas[i][j]==2)sx=i,sy=j;
      }
    }
    ans=11;
	mas[sx][sy]=0;
    bfs(1,P(sx,sy));
    if(ans>=11)cout << -1 << endl;
    else cout << ans << endl;
  }
}
void bfs(int cnt,P p){
  if(cnt >= ans)return;
  for(int i=0;i<4;i++){
    int nx=p.first+dx[i],ny=p.second+dy[i];
    if((!(nx>=0&&nx<h&&ny>=0&&ny<w))||mas[nx][ny]==1)continue;
    HM=0;
    P p1 = move(P(nx,ny),i);
    if(HM==1)continue;
    nx=p1.first; ny=p1.second;
    if(mas[nx][ny]==3){
      ans = cnt;
      return;
    }
    if(mas[nx][ny]==1){
      mas[nx][ny]--;
      bfs(cnt+1,P(nx-dx[i],ny-dy[i]));
      mas[nx][ny]++;
    }
  }
  return;
}
P move(P p,int i){
  while(1){
    if(!(p.first>=0&&p.first<h&&p.second>=0&&p.second<w)){
      HM=1;
      return p;
    }
    if(mas[p.first][p.second]!=0)return p;
    p.first+=dx[i];
    p.second+=dy[i];
  }
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(){
    int l,m,n;
    int k[12];
    while(cin >> l){
        if(l==0)
            break;
        for(int i=0;i<12;i++){
            cin >> m >> n;
            k[i]=m-n;
        }
        for(int i=0;i<12;i++){
            l -= k[i];
            if(l<=0){
                cout << i+1 << endl;
                break;
            }
        }
        if(l>0)
            cout << "NA" << endl;
    }
}

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

const int INF = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int x[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> x[i];
  }

  int ans = INF;
  for ( int p = 1; p <= 100; p++ ) {
    int sum = 0;
    for ( int i = 0; i < n; i++ ) {
      sum += (x[i]-p)*(x[i]-p);
    }
    ans = min(sum, ans);
  }

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


Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    S=input()
    n=len(S)
    if(n==1):
        print(1)
        return

    # dp
    S='#'+S # 1-indexed
    dp1=[0]*(n+1)
    dp2=[0]*(n+1)
    dp1[1]=1
    dp2[2]=1
    if(S[0]==S[1]): dp1[2]=2

    for i in range(2,n+1):
        if(S[i]!=S[i-1]):
            dp1[i]=max(dp1[i-1],dp2[i-1])+1
        else:
            dp1[i]=dp2[i-1]+1
        dp2[i]=dp1[i-2]+1

    print(max(dp1[-1],dp2[-1]))
resolve()

Measured memory_bytes: 44144
c = input()
f = int(c[:2])
e = int(c[2:]) 

if (0<f<13) and (0<e<13):
    print("AMBIGUOUS")
elif (0<f<13):
    print("MMYY")
elif(0<e<13):
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
n=int(input())
march=[0,0,0,0,0]
for i in range(n):
  s=input()
  if s[0]=="M":
    march[0]+=1
  elif s[0]=="A":
    march[1]+=1
  elif s[0]=="R":
    march[2]+=1
  elif s[0]=="C":
    march[3]+=1
  elif s[0]=="H":
    march[4]+=1
finalans=0
for i in range(2**5):
  ans=1
  count=0
  for j in range(5):
    if ((i>>j)&1):
      ans*=march[j]
      count+=1
  if count!=3:
    ans=0
  finalans+=ans
print(finalans)
      

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

bool judge(int a) {
  if (a % 10 != a / 10000)
    return false;
  else
    return (a / 10) % 10 == (a / 1000) % 10;
}

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; ++i) {
    if (judge(i))
      count += 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>

using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int dx, dy;
  dx = x2 - x1;
  dy = y2 - y1;

  int x3, y3, x4, y4;
  x3 = x2 - dy;
  y3 = y2 + dx;
  x4 = x3 - dx;
  y4 = y3 - dy;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

  return 0;
}

Measured memory_bytes: 256
-- Question A

import Control.Applicative
import Control.Monad

main = do
  [n ,p] <- (map read . words) <$> getLine ::IO[Integer]
  xs <- (map read . words) <$> getLine ::IO[Integer]
  putStrLn $ show (counts' n p (ys0 xs) (ys1 xs))
  

ys0 xs = length (filter even xs)
ys1 xs = length (filter odd xs)

counts' a b c d 
 |((b == 1) && (d == 0)) = 0
 |((b == 0) && (d == 0)) = 2^(c)
 | c == 0 = (2^(d) `div` 2)
 | otherwise = 2^(c)*(2^(d) `div` 2)

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a[n],s[n+5];
	s[0]=0LL;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		s[i+1]=s[i]+a[i];
	}
	long long ans=s[n];
	int l=1,r=3;
	for (int i = 2; i < n-1; ++i)
	{
		while (l<i-1)
		{
			if (abs(s[l]-s[i]+s[l])<abs(s[l+1]-s[i]+s[l+1]))
			{
				break;
			}
			++l;
		}
		long long ll=s[l],lr=s[i]-s[l];
		while (r<n)
		{
			if (abs(s[r]-s[i]-s[n]+s[r])<abs(s[r+1]-s[i]-s[n]+s[r+1]))
			{
				break;
			}
			++r;
		}
		long long rl=s[r]-s[i],rr=s[n]-s[r];
		ans=min(ans,max({ll,lr,rl,rr})-min({ll,lr,rl,rr}));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int asc(const void *a, const void *b)
{
    return *(long int *)a - *(long int *)b;
}
int dis(const void *a, const void *b)
{
    return *(long int *)b - *(long int *)a;
}
int main()
{
    double a, b;
    double h, m;
    scanf("%lf %lf %lf %lf", &a, &b, &h, &m);
    double rad;
    rad = 2 * M_PI * (m / 60.0 - (h + m / 60.0) / 12.0);
    printf("%.10lf", sqrt(a * a + b * b - 2 * a * b * cos(rad)));
    return 0;
}

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


vector<vector<int>> g(100010);

vector<bool> vis(100010);

int k;

long long  dfs(int s){
  long long int res=k;
  
  stack<int> st;
  
  st.push(s);
  
  vis[s]=true;
  
  while(!st.empty()){
    
    int p=st.top();
    
    st.pop();
    
    int ans=0;
    
    for(auto x:g[p]){
      if(!vis[x]){
        if(p==s){
          res*=(k-1-ans);
        }
        else{
          res*=(k-2-ans);
        }
        
        res %=1000000007;
        vis[x]=true;
        ans++;
        st.push(x);
      }
    }
  }
  return res;
}

int main(){
  int n;
  cin >> n >> k;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cout << dfs(0) << endl;
}


Measured memory_bytes: 6520
#ABC 121, B - can you solve this
n, m, c = map(int, input().split(' '))
B = [int(el) for el in input().split(' ')]

A = [[int(el) for el in input().split(' ')] for i in range(n)]
count = 0
for i in range(n):
    total = c
    for a, b in zip(A[i],B):
        total += a*b
    if total > 0:
        count += 1
print(count)


Measured memory_bytes: 3188
using System;

class Plogram
{
    static void Main()
    {
        string[] ARRAY = Console.ReadLine().Split(' ');
        string[] array = Console.ReadLine().Split(' ');

        int H = int.Parse(ARRAY[0]);
        int W = int.Parse(ARRAY[1]);
        int h = int.Parse(array[0]);
        int w = int.Parse(array[1]);

        Console.WriteLine(H * W - (h * W + H * w - h * w));
    }
}

Measured memory_bytes: 13140
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> x(n+1), y(n+1);
    for(int i = 0; i < n; i++){
        x[i+1] = x[i] + a[i];
        y[i+1] = y[i] + max(0LL, a[i]);
    }

    int ans = 0;
    for(int i = 0; i <= n - k; i++){
        int tmp = max(0LL, x[i+k] - x[i]);
        tmp += y[i] + y[n] - y[i+k];
        if(tmp > ans){
            ans = tmp;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560