akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
c = list(map(lambda x: int(x) - 1, input().split()))
query = []
for i in range(q):
    l, r = map(lambda x: int(x) - 1, input().split())
    query.append(l << 40 | r << 20 | i)

query.sort()
ball = [list() for i in range(n)]
for i, x in enumerate(c):
    ball[x].append(i)

# binary indexed tree
bit = [0] * (n + 1)
def add(i, x):
    i += 1
    while i <= n:
        bit[i] += x
        i += i & -i

def get(i):
    i += 1
    s = 0
    while i:
        s += bit[i]
        i -= i & -i
    return s

for i in ball:
    if i:
        add(i[0], 1)
        i.reverse()

at = 0
ans = [0] * q
for x in query:
    l = x >> 40
    r = x >> 20 & 0xfffff
    i = x & 0xfffff
    while at < l:
        b = ball[c[at]]
        add(b[-1], -1)
        b.pop()
        if b:
            add(b[-1], 1)
        at += 1
    ans[i] = get(r) - get(l - 1)

for i in ans:
    print(i)

Measured memory_bytes: 197652
n=int(input())
s=input()
c=[]
for i in range(n-1):
    a=s[:i]
    b=s[i:]
    c.append(set(a)&set(b))
#print(c)
d=[]
for i in range(len(c)):
    d.append(len(c[i]))
print(max(d))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  vector<int> ans(100000000,0);
  ans[s]++;
  for(int i=0;i<1000000;i++){
    if(s%2==0){
      s/=2;
      ans[s]++;
    }else{
      s=3*s+1;
      ans[s]++;
    }
    if(ans[s]==2){
      cout<<i+2<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 393876
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC101_A solver = new ABC101_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC101_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char[] array = in.nextLine().toCharArray();

            int ans = 0;
            for (char c : array) {
                if (c == '+') {
                    ans++;
                } else {
                    ans--;
                }
            }
            out.print(ans);
        }

    }
}



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

typedef long long ll;
typedef pair<int,int> pii;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;
    vector<int> vec;
    for (ll i = 2; i * i <= n; i++) {
        int c = 0;
        while (n % i == 0) {
            ++c;
            n /= i;
        }
        if (c > 0)
            vec.push_back(c);
    }
    if (n > 1)
        vec.push_back(1);
    int ans = 0;
    for (int it: vec) {
        int i = 1;
        while (it > 0) {
            ++ans;
            it -= i;
            i++;
            if (it < i)
                break;
        }
    }
    cout << ans;

    return 0;
}


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

int main(){
 string str;
 
 getline(cin,str);
 for(int i=0;i<(int)str.size();i++){
 if(islower(str[i])){
 str[i]=toupper(str[i]);
 }else if(isupper(str[i])){
 str[i]=tolower(str[i]);
}
}
cout<<str<<endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
using LL = long long;
int main()
{
	LL n, k;
	cin >> n >> k;
	if (n >= k)
	{
		LL t = n / k;
		n -= t * k;
		printf("%lld\n", min(abs(n - k), n));
	}
	else
	{
		printf("%lld\n", min(abs(n - k), n));
	}


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	char str[100], t;
	scanf("%d%*c", &n);
	if(n < 2 || n%2 == 1) {
		printf("No");
		return 0;
	}

	for(int i=0;i<n/2;i++) {
		scanf("%c", &str[i]);
	}
	for(int i=0;i<n/2;i++) {
		scanf("%c", &t);
		if(str[i] != t) {
			printf("No");
			return 0;
		}
	}

	printf("Yes");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans=1;
    for(int i=1;i<n;i++)if(s[i]!=s[i-1])ans++;
    cout << ans;


}

/*



 */



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.nextLine();
        String[] strs = sc.nextLine().split(" ");
        int min = 1000000000;
        for (String str : strs) {
            int result = countDiv(Integer.valueOf(str));
            if(min > result){
                min = result;
            }
            if(result == 0){
            	break;
            }
        }
        System.out.println(min);
        
        
        sc.close();
    }

    public static int countDiv(int i){
        if(i == 0) {
            return 0;
        }
        int cnt=0;
        while(i%2 == 0) {
          	i = i/2;
            cnt++;
        }
        return cnt;
    }
}

Measured memory_bytes: 21972
def main():
    n = int(input())
    P = [int(x) for x in input().split()]
    minv = 2 * 10 ** 5 + 1
    cnt = 0
    for i in range(n):
        if minv > P[i]:
            minv = P[i]
            cnt += 1
    print(cnt)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 32236
/*#include<bits/stdc++.h>
#define sf1(x)      scanf("%d",&x)
#define sf2(x,y)    scanf("%d %d",&x,&y)
#define sf3(x,y,z)  scanf("%d %d %d",&x,&y,&z)
#define pcase(x)    printf("Case %d: ",x)
#define pf          printf
#define pf1(x)      printf("%d\n",x)
#define pf1s(x)     printf("%d ",x)
#define pf2(x,y)    printf("%d %d\n",x,y)
#define pf3(x,y,z)  printf("%d %d %d\n",x,y,z)
#define FOR(i,x)    for(int i=0;i<x;i++)
#define FOR1(i,x)   for(int i=1;i<=x;i++)
#define FORr(i,x)   for(int i=n; i>=1;i--)
#define pb          push_back
using namespace std;
int main()
{
    int n,a,b;
    string s;
    stack<int>st;
    while(cin>>s){
        if(s=="+"){
           a=st.top();  st.pop();
           b=st.top();  st.pop();
           st.push(a + b);
        }
        else if(s=="-"){
           a=st.top();  st.pop();
           b=st.top();  st.pop();
           st.push(a+b);
        }
        else if(s=="*"){
           a=st.top();  st.pop();
           b=st.top();  st.pop();
           st.push(a+b);
        }
        else st.push(atoi(s.c_str()));
    }
    cout<<st.top()<<endl;
    return 0;
}*/
#include<iostream>
#include<string>
#include<stack>
#include<cstdlib>
using namespace std;

int main()
{
    string s;
    stack<int>st;
    while (cin>>s) {
        if (s == "+") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(a + b);
        }
        else if (s == "-") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b-a);
        }
        else if (s== "*") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(a*b);
        }
        else {
            st.push(atoi(s.c_str()));
        }
    }
    cout << st.top() << endl;
    return 0;
}

Measured memory_bytes: 3200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Sample201
{
    class Program
    {
        static void Main(string[] args)
        {
          long h;
            string[] str = Console.ReadLine().Split(' ');
          h = long.Parse(str[0]);
          
          long ans = 0;
          int count = 0;
          while(true){
            ans += (long)Math.Pow(2, count);
           if(h==1){
           break;
           } 
            h /= 2;
            count++;
          }


          Console.WriteLine(ans);
          
          
        }
    }
}


Measured memory_bytes: 13140
/*  -*- coding: utf-8 -*-
 *
 * 1378.cc: Secret of Chocolate Poles
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_L = 100;

/* typedef */

typedef long long ll;

enum { WH, BL };

/* global variables */

ll dp[MAX_L + 1][2];

/* subroutines */

/* main */

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

  dp[0][WH] = 1, dp[0][BL] = 0;
  for (int i = 0; i < l; i++) {
    dp[i + 1][WH] += dp[i][BL];
    dp[i + 1][BL] += dp[i][WH];
    if (i + k <= l) dp[i + k][BL] += dp[i][WH];
  }

  ll sum = 0;
  for (int i = 1; i <= l; i++) sum += dp[i][BL];

  printf("%lld\n", sum);
  return 0;
}



Measured memory_bytes: 3232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] numMonsters = new int[N+1];
		int[] capasityHero = new int[N];		
		for(int i=0;i<N+1;i++) {
			numMonsters[i] = sc.nextInt();
		}		
		for(int i=0;i<N; i++) {
			capasityHero[i] = sc.nextInt();
		}
		
		long sum = 0;
		for(int i=0;i<N;i++) {
			int defeatsMain = Math.min(numMonsters[i], capasityHero[i]);
			sum += defeatsMain; 
			int exPower = capasityHero[i] - defeatsMain;
			int defeatsSub = Math.min(numMonsters[i+1], exPower);
			sum += defeatsSub;
			numMonsters[i+1] = numMonsters[i+1] - defeatsSub;
		}
		
		System.out.println(sum);
		
		sc.close();	
	}

}

Measured memory_bytes: 64172
from collections import Counter
import itertools
n = int(input())
ary = []
for i in range(n):
    x = input()[0]
    if x == "M" or x =="A" or x =="R" or x =="C" or x == "H":
        ary.append(x)
c = Counter(ary)
cmb = itertools.combinations(c.keys(),3)
ans = 0
for s in cmb:
    ans += c[s[0]]*c[s[1]]*c[s[2]]
print(ans)

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll          long long int
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{	ios
  ll n,k ;
  cin>> n>>k ;
  vector <ll> v(n,0) ;
  for(ll i=0;i<n;i++)
  {
    cin>> v[i] ;
  }
  vector <ll> a(n,INT_MAX) ;
  a[0]=0 ;
  a[1]= abs(v[1]-v[0]) ;
  for(ll i=2;i<n;i++)
  {
    for(ll j=1 ; j<i+1 && j< k+1; j++)
  	{
   		a[i]= min(a[i],a[i-j]+abs(v[i]-v[i-j])) ; 
  	}
  }
  cout<< a[n-1] ;
	return 0 ;
}


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

using namespace std;

#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define f(n) for(int i=0;i<n;++i)
#define f2(n) for(int j=0;j<n;++j)
#define f3(n) for(int k=0;k<n;++k)
#define F(i,x,n,y) for(i=x;i<n;i+=1)
#define fi(i) for(i=0;i<n;++i)
#define fa(x,y) for(auto x:y)

//Warsaw debug template
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1,debug&>::type operator<<(c i){
sim > struct rge {c b,e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
#ifdef LOCAL
~debug() {cerr<<endl; }
eni(!=) cerr<< boolalpha << i; ris;}
eni(==) ris <<range(begin(i),end(i)); }
sim, class b dor(pair<b,c> d){
ris<<"("<<d.first<<","<<d.second<<")";
}
sim dor(rge<c> d){
    *this << "[";
    for(auto it=d.b;it!=d.e;++it)
        *this <<"," +(it==d.b)<< *it;
    ris<<"]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) "["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"
//End of debug template        
    

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    if(n<=999) cout<<"ABC";
    else cout<<"ABD";
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
S = '_' + input()
### dp[i文字目まで読んだ][直前に読んだ文字] = 分割数
dp = []
for _ in range(len(S) + 1):
    dp += [{}]
if len(S) == 2:
    print(1)
else:
    dp[2][S[1:2]] = 1
    dp[3][S[1:3]] = 1
    index = 2
    while index < len(S):
        for k, v in dp[index].items():
            if index + 1 <= len(S):
                s = S[index: index + 1]
                # print(f"index:{index} k:{k} v:{v} s:{s}", file=sys.stderr)
                if s != k:
                    if not s in dp[index + 1]:
                        dp[index + 1][s] = v + 1
                    elif s in dp[index + 1] and dp[index + 1][s] < v + 1:
                        dp[index + 1][s] = v + 1
            if index + 2 <= len(S):
                s = S[index: index + 2]
                if s != k:
                    if not s in dp[index + 2]:
                        dp[index + 2][s] = v + 1
                    elif s in dp[index + 2] and dp[index + 2][s] < v + 1:
                        dp[index + 2][s] = v + 1
        index += 1
    # print(f'len:{len(S)} dp:{dp}', file=sys.stderr)
    print(max([v for k, v in dp[-1].items()]))

Measured memory_bytes: 88148
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
X = [1] * (W + 2)
for _ in range(H):
    X += [1] + [1 if a == "@" else 0 for a in input()] + [1]
X += [1] * (W + 2)
H, W = H+2, W+2
s, t = x1 * W + y1, x2 * W + y2

def BFS(i0=0):
    dd = [(), (1, -1), (W, -W), (1, -1, W, -W)]
    Q = deque([(i0, 3)])
    D = [-1] * (H * W)
    D[i0] = 0
    while Q:
        x, t = Q.popleft()
        if t & 1:
            for d in (1, -1):
                for y in range(x + d, x + d * K, d):
                    if X[y]: break
                    if D[y] == -1:
                        D[y] = D[x] + 1
                        Q.append((y, 2))
                else:
                    y = x + d * K
                    if X[y] == 0:
                        if D[y] == -1:
                            D[y] = D[x] + 1
                            Q.append((y, 3))
        if t & 2:
            for d in (W, -W):
                for y in range(x + d, x + d * K, d):
                    if X[y]: break
                    if D[y] == -1:
                        D[y] = D[x] + 1
                        Q.append((y, 1))
                else:
                    y = x + d * K
                    if X[y] == 0:
                        if D[y] == -1:
                            D[y] = D[x] + 1
                            Q.append((y, 3))
                        
    return D

print(BFS(s)[t])

Measured memory_bytes: 162500
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<list>
using namespace std;

#define BACK 'B'

int main(void)
{
	string s;
	cin >> s;

	list<char> ret;
	for(auto it=s.begin(); it!=s.end(); it++)
	{
		if(*it != BACK)
			ret.push_back(*it);
		else if(ret.empty() != true)
			ret.pop_back();
			
	}

	for(auto it=ret.begin(); it!=ret.end(); it++)
		cout << *it;
	cout << endl;

	return 0;
}


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

using namespace std;

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

    vector<int> W(N,0);

    for(int i=0;i<N;i++)
    {
        cin >> W.at(i);
    }

    int total = accumulate(W.begin(),W.end(),0);

    vector<int> answers(N);

    for(int i=0;i<N;i++)
    {
        total -= W.at(i)*2;
        answers.at(i) = abs(total);
    }

    cout << *min_element(answers.begin(),answers.end()) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int N = sc.nextInt();
        int W = sc.nextInt();
        int H = sc.nextInt();
        int numways = ((N-W)+1) * ((N-H)+1);
      if(numways<0){
        numways = 0;
      }
        System.out.println(numways);
        
    }

}


Measured memory_bytes: 22868
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		while(h != 0 || w != 0){

			StringBuilder sb = new StringBuilder();

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

				for(int j = 0; j < w; j++){
					if(j == 0 || j == w - 1 || i == 0 || i == h - 1){
						sb.append("#");
					}else{
						sb.append(".");
					}
				}
				sb.append("\n");

			}
			System.out.println(sb);

			h = sc.nextInt();
			w = sc.nextInt();
		}
	}
}

Measured memory_bytes: 20736
n = int(input())
a = list(map(int, input().split()))
from itertools import accumulate
b = [0]
b.extend(list(accumulate(a)))
b.sort()
ans = 0
cur = 1
for i in range(len(b)-1):
  if b[i]==b[i+1]:
    cur+=1
  else:
    if cur>1:
      ans+=(cur*(cur-1))//2
    cur=1
if cur>1:
  ans+=(cur*(cur-1))//2
print(ans)

Measured memory_bytes: 25724
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var S, T [3]string
	line := nextLine()
	for pos, c := range line {
		S[pos] = string([]rune{c})
	}
	line = nextLine()
	for pos, c := range line {
		T[pos] = string([]rune{c})
	}

	ans := 0
	for i := 0; i < 3; i++ {
		if S[i] == T[i] {
			ans++
		}
	}
	fmt.Printf("%d", ans)

}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		PriorityQueue<Integer> stock = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    stock.add(- sc.nextInt());
		}
		for (int i = 0; i < m; i++) {
		    stock.add(stock.poll() / 2);
		}
		long sum = 0;
		while (stock.size() > 0) {
		    sum -= stock.poll();
		}
		System.out.println(sum);
   }
}


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

int main() {
  int m, d;
  cin >> m >> d;
  int r = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 10; j <= d; j++) {
      r += j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i;
    }
  }
  cout << r << endl;
}


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int d, n;
  cin >> d >> n;

  if (n == 100) n++;

  p((int)pow(100, d) * n);
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())
#define pb push_back
#define mp make_pair
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
#define endl "\n"

using namespace std;

const int N = 500510;
const int inf = (int)(1e18) + 123;
const int mod = 998244353;
const double eps = 1e-9;

int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}

map <int, int> M;

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    int g = gcd(n, m);
    for(int i = 2; i * i <= g; ++i) {
        if (g % i == 0) {
            while (g % i == 0) {
                g /= i;
                M[i]++;
            }
        }
    }
    if (g != 1) {
        M[g]++;
    }
    cout << sz(M) + 1;

    return 0;
}

Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())
zisin = 30*h + 0.5*m
hunnsinn = 6*m
diff = abs(zisin-hunnsinn)

c2 = a**2 + b**2 -2*a*b*math.cos(math.radians(diff))
print(pow(c2, 0.5))

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

using namespace std;
#ifdef ONLINE_JUDGE
#define cerr if(false)cerr
#endif
#define int long long
#define ld1 long double
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout<<setprecision(14);
#define cint int t;cin>>t;while(t--)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
#define N (int)1e5+7
#define MAXN (int)5004
#define INF (int)1e9
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define endl '\n'
#define vcc vector<char>

const int mod=1000000007;
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;

    if(a>=k) cout<<k<<endl;
    else{
        k-=a;
        k-=b;
        if(k<=0) cout<<a<<endl;
        else cout<<a-k<<endl;
    }
}


int32_t main() {
    faster;

#ifndef ONLINE_JUDGE
    READ("inp.txt");
    WRITE("out.txt");
    double beg=clock();
#endif

    int t=1;
//    cin>>t;

    while(t--){
        solve();
    }

#ifndef ONLINE_JUDGE
    double end=clock();
    cout<<endl;
    cerr<<"*** Total time = "<<(end-beg)/CLOCKS_PER_SEC;
#endif
}


Measured memory_bytes: 3652
#include <stdio.h>

int main()
{
   long int flag=1,a,b,c,i=0,j=0,k=0;
    char a2[101],b2[101],c2[101];
    gets(a2);
    gets(b2);
    gets(c2);
    a=strlen(a2);
    b=strlen(b2);
    c=strlen(c2);
    while(1)
    {
        if(flag==1)
        {
            if(i==a)
            {
                  printf("A");
                  return 0;
            }else{
            if(a2[i]=='a')
            {
                flag=1;
                i++;
             
            }else{
                if(a2[i]=='b')
                {
                    flag=2;
                     i++;
                }else{
                    flag=3;
                     i++;
                }
            }
            }
           
            
        }else{
        if(flag==2)
        {
            if(j==b)
            {
                  printf("B");
                  return 0;
            }else{
            if(b2[j]=='a')
            {
                flag=1;
                j++;
             
            }else{
                if(b2[j]=='b')
                {
                    flag=2;
                     j++;
                }else{
                    flag=3;
                     j++;
                }
            }
            
            }
        }
       
       else
        {  
            if(k==c)
            {
                  printf("C");
                  return 0;
            }else{
            if(c2[k]=='a')
            {
                flag=1;
                k++;
             
            }else{
                if(c2[k]=='b')
                {
                    flag=2;
                     k++;
                    
                }else{
                    flag=3;
                     k++;
                }
            }
            }
        }
        }
    }

    return 0;
}

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

int main()
{
	int N;
	int K;
	int X;
	int Y;
	cin >> N;
	cin >> K;
	cin >> X;
	cin >> Y;
	if (N > K)
	{
		cout << K*X + N*Y - K*Y << endl;
	}
	else
	{
		cout << N*X << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int bitcount(int n){
    n = (n & 0x55555555) + (n >> 1 & 0x55555555);
    n = (n & 0x33333333) + (n >> 2 & 0x33333333);
    n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f);
    n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff);
    return (n & 0x0000ffff) + (n >>16 & 0x0000ffff);
}

int main(){
    int n;
    cin >> n;
    vector<int> f(n, 0);
    for(int i=0; i<n; i++){
        for(int j=0; j<10; j++){
            int a;
            cin >> a;
            f[i] = f[i]*2 +a;
        }
    }
    vector<vector<int> > p(n, vector<int>(11));
    for(int i=0; i<n; i++){
        for(int j=0; j<=10; j++){
            cin >> p[i][j];
        }
    }

    int ans=-inf;
    for(int i=1; i<(1<<10); i++){
        int subans = 0;
        for(int j=0; j<n; j++){
            subans += p[j][bitcount(i & f[j])];
        }
        ans = max(ans, subans);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w;
int n;
char field[1001][1001];
int sx,sy;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int bfs(char tn){
	queue<P> que; que.push(P(sx,sy));
	int d[1001][1001];
	for (int i = 0;i < h;i++){
		for (int j = 0;j < w;j++){
			d[i][j] = INT_MAX;
		}
	}
	d[sy][sx] = 0;
	while(!que.empty()){
		P p = que.front(); que.pop(); 
		int x = p.first, y = p.second;
		//cout << x << " " << y << endl;
		if(field[y][x] == tn){
			sx = x; sy = y;
			return d[y][x];
		}
		for (int i = 0;i < 4;i++){
			int nx = x+dx[i], ny = y+dy[i];
			//cout << nx << " " << ny << endl;
			if(nx >= 0 && ny >= 0 && nx < w && ny < h && d[ny][nx] == INT_MAX && field[ny][nx] != 'X'){
				d[ny][nx] = d[y][x]+1;
				que.push(P(nx,ny));
			}
		}
	}
	return -1;
}

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

	cin >> h >> w >> n;

	for (int i = 0;i < h;i++){
		for (int j = 0;j < w;j++){
			cin >> field[i][j];
			if(field[i][j] == 'S'){
				sx = j; sy = i;
			}
		}
	}

	int ans = 0;

	for (int i = 1;i <= n;i++){
		ans += bfs('0'+i);
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 8040
#include<stdio.h>
#include<vector>

using namespace std;

int pow_n(int i,int j)
{
	int b=1;

	for(int a=0;a<j;a++)
	{
		b*=i;
	}

	return b;
}

int main()
{
	int n,k,t,sn=0;
	vector<int> vec;

	scanf("%d",&n);
	k=n;

	for(int a=0;a<10;a++)
	{
		if(n>=pow_n(10,9-a))
		{
			t=k/pow_n(10,9-a);
			vec.push_back(t);

			k=k%pow_n(10,9-a);
		}
	}

	for(int a=0;a<vec.size();a++)sn+=vec[a];

	if(n%sn==0)printf("Yes\n");
	else printf("No\n");

	return 0;
}

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

using namespace std;

int main()
{
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);

	int k;
	cin >> k;
	for (int i = 0; i < k; i++) {
		a[2] *= 2;
	}
	cout << a[0] + a[1] + a[2] << endl;

	return 0;
}

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

int H,W;
char fid[20][20] = {0};
bool visit[20][20] = {0};

int main()
{
    scanf("%d%d",&H,&W);
    for(int i = 0; i < H; i++)for(int j = 0; j < W; j++)scanf(" %c",&fid[i + 1][j + 1]);
    int x = 1,y = 1;
    if(fid[1][1] != '#')
    {
        printf("Impossible\n");
        return 0;
    }
    for(int i = 0; i < H; i++)for(int j = 0; j < W; j++)if(fid[i + 1][j + 1] == '#')x++;
    if(W + H == x)printf("Possible\n");
    else printf("Impossible\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
  val cin = Scanner(System.`in`)
  val a = cin.nextInt()
  val b = cin.nextInt()

  if (a + b in 0..9) {
    println(a + b)
  } else {
    println("error")
  }

  cin.close()
}

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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,cnt=0;
	cin >> n >> m;
	vector<int> A(n+1);
	for(int i=1;i<=n;i++){
		cin >> A[i];
		A[i]+=A[i-1];
		if(A[i]<=m)
			cnt++;
	}
	cout << cnt+1 << '\n';
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




















Measured memory_bytes: 256
s = list(input().split())
l = len(s[0])
for i in range(l):
    if i % 2 == 1:
        if s[0][i] == "R":
            print("No")
            exit()
    else:
        if s[0][i] == "L":
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

def check(string):
    if string[-5:] == "dream":
        new = string[:-5]
        return new

    if string[-7:] == "dreamer":
        new = string[:-7]
        return new

    if string[-5:] == "erase":
        new = string[:-5]
        return new

    if string[-6:] == "eraser":
        new = string[:-6]
        return new

    print("NO")


if __name__ == '__main__':
    s = str(input())

    while s:
        s = check(s)

    if s == "":
        print("YES")


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int N,Q,K;
typedef struct edge{
    int to,cost;
}Edge;
vector<Edge> adj[MAX+2];
ll d[MAX+2]; //Kからの距離
bool visited[MAX+2];
void dfs_k(int l,ll dist){ //今の場所,そこのkからの距離

    for(int i=0;i<adj[l].size();i++){
        int v=adj[l][i].to; //lに隣接した次の場所
        int cos=adj[l][i].cost; //lからvに行くときのcost
        if(visited[v]) continue; //行ったことある
        
        visited[v]=true;
        d[v]=1ll*(dist+cos);
        dfs_k(v,d[v]);
        

    }
    
}

void solve(){
    visited[K]=true;
    d[K]=0;
    dfs_k(K,0ll);
}

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        Edge e1,e2;
        e1.to=b,e1.cost=c;
        e2.to=a,e2.cost=c;
        
        adj[a].push_back(e1);
        adj[b].push_back(e2); //反対向きがあることに注意!!
    }
    cin>>Q>>K;
    solve();
    

    while(Q--){
        int x,y;
        cin>>x>>y;
        cout<<d[x]+d[y]<<"\n";
        
    }
    
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int r, g, b;
	cin >> r >> g >> b;

	if ((r*100 + g*10 + b) % 4 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < n; i++)
#define Rep(i,n) for (int i = n; i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define cend cout<<endl;
#define P pair<int, int>
#define prique priority_queue<P, vector<P>, greater<P>>
struct edge { int to, cost; };
using namespace std;
int n, m;
int par[100010], ranked[100010], sizeth[100010];
set<int>st;
void init(int n) {
	rep(i, n) {
		par[i] = i;
		ranked[i] = 0;
		sizeth[i] = 1;
	}
}

int root(int x) {
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

bool same(int x, int y) {
	return root(x) == root(y);
}

void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	if (ranked[x] < ranked[y]) {
		par[x] = y;
		sizeth[y] += sizeth[x];
	}
	else {
		par[y] = x;
		if (ranked[x] == ranked[y]) ranked[x]++;
		sizeth[x] += sizeth[y];
	}
}
signed main() {
	cin >> n >> m;
	init(n);
	rep(i, m) {
		int x, y, z;
		cin >> x >> y >> z;
		x--;
		y--;
		unite(x, y);
	}
	rep(i, n) st.insert(root(i));
	cout << st.size() << endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

set<pair<ll,ll>>a;
map<pair<ll,ll>,ll>b;
ll c[10];
int main() {
	ll h,w,n;
	cin>>h>>w>>n;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		x--,y--;
		a.insert(make_pair(x,y));
	}
    for(auto itr = a.begin(); itr != a.end(); ++itr) {
        pair<ll,ll>now= *itr;
        ll nowx=now.first;
        ll nowy=now.second;
        //cout << nowx<<" "<<nowy<<endl;
        for(int i=-1;i<=1;i++){
        	for(int j=-1;j<=1;j++){
        		ll cnt=0;
        		ll x=nowx+i;
        		ll y=nowy+j;
        		if(x-1<0||x+1>h-1||y-1<0||y+1>w-1){
        			continue;
        		}
        		//cout << x<< " "<< y<<endl;         		
        		for(int k=-1;k<=1;k++){
        			for(int l=-1;l<=1;l++){
        				ll chx=x+k;
        				ll chy=y+l;
        				if(a.count(make_pair(chx,chy))==1){
        					cnt++;
        				}
        			}
        		}
        		//cout << cnt<<endl;
        		b[make_pair(x,y)]=cnt;
        	}
        }
    }
    ll cnt=(h-2)*(w-2);
    for(auto itr = b.begin(); itr != b.end(); ++itr) {
       ll now= itr->second ;
       //cout <<now;
       c[now]++;
    }
    for(int i=0;i<10;i++){
    	ll now=c[i];
    	cnt-=now;
    }
    c[0]=cnt;
    for(int i=0;i<10;i++){
    	cout << c[i]<<endl;
    }
	return 0;
}

Measured memory_bytes: 62720
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    X, Y = map(int, input().split())
    A = [1, 3, 5, 7, 8, 10, 12]
    B = [4, 6, 9, 11]
    C = [2]
    print('Yes' if any([(X in A and Y in A),
                        (X in B and Y in B),
                        (X in C and Y in C)])else 'No')


if __name__ == "__main__":
    main()


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

static const int MAX = 100;

void printStringnum(int a[],int n){
    for(int i=0;i<n-1;i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] <<"\n";
}

void inserstionSort(int a[],int n){
    int v,j;
    for(int i=1;i<n;i++){
        printStringnum(a,n);
        v = a[i];
        j = i-1;
        while(j>=0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
    }
    printStringnum(a,n);
}

int main(){
    int n;

    cin >> n;
    
    int a[MAX];

    for(int i=0;i<n;i++){
    cin >> a[i];
    //cout << a[i];
    }

    inserstionSort(a,n);
    }


Measured memory_bytes: 3088
int linearSearch(int );

int S[100000],n;

int main(){

  int i,j,q,T[50000],C;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
    for(i=0;i<q;i++){
      scanf("%d",&T[i]);
      if((linearSearch(T[i]))==0)
      C++;
    }
    printf("%d\n",C);
    return 0;
}

int linearSearch(int key){
  int i=0;
  S[n]=key;
  while(S[i]!=key){
    i++;
    if(i==n)
      return 1;
  }
  return 0; 
  }

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define INF 1007654321
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }

int main() {
    FAST_IO();
    int N, K; cin >> N >> K;
    ll ans = 0;
    if(K == 0) {
        cout << 1LL*N*N << "\n";
        return 0;
    }
    repp(b, K + 1, N) {
        // a = b*q + r (K <= r < b)
        ans += 1LL * (b - K) * ((N - b + 1) / b + 1);
        ans += max(0, N - b * ((N - b + 1) / b + 1) - K + 1);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

typedef pair<int, int> P;


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

	if (a == 1 && b == 2 || a == 2 && b == 1)
	{
		cout << 3 << endl;
	}
	else if (a == 2 && b == 3 || a == 3 && b == 2)
	{
		cout << 1 << endl;
	}
	else 
	{
		cout << 2 << endl;
	}


	return 0;
}

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

int main(void) {
  int num;
  cin >> num;

  int room[4][3][10] = {};
  int b, f, r, v;
  for(int i = 0; i < num; i++) {
    cin >> b >> f >> r >> v;
    room[b-1][f-1][r-1] += v;
  }

  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 3; j++) {
      for(int k = 0; k < 10; k++) {
        cout << " " << room[i][j][k];
      }
      cout << endl;
    }
    if(i != 3) {
      cout << "####################" << endl;
    }
  }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    map<int,bool> s,g;
    REP(i,m){
        int a, b;
        cin >> a >> b;
        if (a == 1) s[b] = true;
        if (b == n) g[a] = true;

    }

    bool ans = false;
    for(auto x:s) {
        if (g[x.first]) {
            ans = true;
            break;
        }
    }

    string str = ans ? "POSSIBLE" : "IMPOSSIBLE";
    cout << str << endl;

    return 0;
}

Measured memory_bytes: 14336
#include <cstdio>
#include <algorithm>

using namespace std;
const int N = 100010;
int n;

int cnt[N][2];
int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;++i){
		int x;
		scanf("%d",&x);
		cnt[x][i & 1]++;
	}
	int cnt0 = 0,cnt1 = 0,cnts0 = 0,cnts1 = 0,cnt0dex,cnt1dex;
	for(int i = 1;i < N;++i)
	{
		if(cnt[i][0] > cnt0){
			cnt0 = cnt[i][0];
			cnt0dex = i;
		}
		if(cnt[i][1] > cnt1){
			cnt1 = cnt[i][1];
			cnt1dex = i;
		}
	}
	if(cnt0dex != cnt1dex){
		printf("%d",n - cnt0 - cnt1);
		return 0;
	}
	cnt[cnt0dex][0] = 0;
	cnt[cnt1dex][1] = 0;
	for(int i = 1;i < N;++i)
	{
		if(cnt[i][0] > cnts0){
			cnts0 = cnt[i][0];
			cnt0dex = i;
		}
		if(cnt[i][1] > cnts1){
			cnts1 = cnt[i][1];
			cnt1dex = i;
		}
	}
	printf("%d",n - max(cnts1 + cnt0,cnts0 + cnt1));
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;string S,T;int f(char a,char b,int c,int d){int l=1,g=d;int N=S.size();for(int i=N-1;i>=0;--i){if(T[i]==a)g=min(d,g+1);else if(T[i]==b)l=max(1,l-1);if(S[i] == a)++l;else if(S[i]==b)--g;if(l>g)return 0;}if(c<l||c>g)return 0;else return 1;}int main(){int H,W,N;cin>>H>>W>>N;int a,b;cin>>a>>b;cin>>S>>T;int r=f('L','R',b,W)&f('U','D',a,H);cout<<(r?"YES":"NO")<<endl;}

Measured memory_bytes: 776
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;

const int Mod = 1e9 + 7;


template <typename T>
class Matrix {
  int n, m;
  vector<vector<T>> mat;
public:
  Matrix(int n): n(n), m(n) { mat.resize(n, vector<T>(m, T())); }
  Matrix(int n, int m): n(n), m(m) { mat.resize(n, vector<T>(m, T())); }
  Matrix(int n, int m, T v): n(n), m(m) { mat.resize(n, vector<T>(m, v)); }
  const vector<T>& operator[](int r) const { return mat[r]; }
  vector<T>& operator[](int r) { return mat[r]; }
  inline int N() { return n; }
  inline int M() { return m; }
  T trace() const {
    T r = T();
    for(int i = 0; i < n; i++)
      r = r + mat[i][i];
    return r;
  }
  Matrix rotate() const {
    Matrix R(m, n, T());
    for(int i = 0; i < n; i++)
      for(int j = 0; j < m; j++)
        R[j][n - 1 - i] = mat[i][j];
    return R;
  }
  Matrix reflect() const {
    Matrix R(n, m);
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        R[i][m - 1 - j] = mat[i][j];
    return R;
  }
  static Matrix identity(int n) {
    Matrix R(n, n, T());
    for(int i = 0; i < R.N(); i++)
      R[i][i] = 1;
    return R;
  }
  friend Matrix operator+ (const Matrix& A, const Matrix& B) {
    Matrix R(A.N(), B.M());
    for(int i = 0; i < R.N(); i++)
      for(int j = 0; j < R.M(); j++)
        R[i][j] = A[i][j] + B[i][j], R[i][j] %= Mod;
    return R;
  }
  friend Matrix operator* (const Matrix& A, const Matrix& B) {
    Matrix R(A.n, B.m);
    for(int i = 0; i < R.n; i++)
      for(int j = 0; j < R.m; j++) {
        R[i][j] = T();
        for(int k = 0; k < R.n; k++)
          R[i][j] = (R[i][j] + A[i][k] * B[k][j]) % Mod;
      }
    return R;
  }
  friend Matrix operator^ (const Matrix& A, long long p) {
    if(!p) return Matrix::identity(A.n);
    if(p & 1) return A * (A ^ (p - 1));
    return (A * A) ^ (p >> 1);
  }
  friend ostream& operator<<(ostream& cout, const Matrix& A) {
    for(int i = 0; i < A.n; i++) {
      for(int j = 0; j < A.m; j++)
        cout << A.mat[i][j] << ' ';
      cout << '\n';
    }
    return cout;
  }
};


int main()
{
  int n;
  long long k;
  cin >> n >> k;
  Matrix<long long> a(n);
  for(int i = 0 ; i < n ; i++)
    for(int j = 0 ; j < n ; j++)
      cin >> a[i][j];
  Matrix<long long> b = a ^ k;
  long long ans = 0;
  for(int i = 0 ; i < n ; i++)
    for(int j = 0 ; j < n ; j++)
      ans += b[i][j], ans %= Mod;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

	vector<int> ts(n + 1, 0), xs(n + 1, 0), ys(n + 1, 0);
	for (int i = 1; i <= n; i++) cin >> ts[i] >> xs[i] >> ys[i];

	bool is_solved = true;
	for (int i = 0; i < n; i++) {
		int dt = ts[i + 1] - ts[i];
		int dist = abs(xs[i + 1] - xs[i]) + abs(ys[i + 1] - ys[i]);
		if (dt < dist || dist % 2 != dt % 2) {
			is_solved = false;
			break;
		}
	}

	string ans = is_solved ? "Yes" : "No";
	cout << ans << endl;


    return 0;
}



Measured memory_bytes: 1536
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n;
vector<int> Go(int m1, int m2, int a, int b) {
	int i;
	vector<int>T, res;
	for (i = 0; i < n; i++) {
		if (!((m1 >> i) & 1))T.push_back(i);
	}
	if (T.size() == 1) {
		res.push_back(a);
		res.push_back(b);
		return res;
	}
	int pv = T[0];

	int ck = (a >> pv) & 1;
	int ck2 = (b >> pv) & 1;

	if (ck != ck2) {
		vector<int>U = Go(m1 | (1 << pv), m2 | (ck << pv), a, a ^ (1<<T[1]));
		vector<int>V = Go(m1 | (1 << pv), m2 | (ck2 << pv), a^(1<<T[1])^(1<<pv), b);
		for (auto &t : U)res.push_back(t);
		for (auto &t : V)res.push_back(t);
		return res;
	}
	else {
		vector<int>U = Go(m1 | (1 << pv), m2 | (ck << pv), a, b);
		vector<int>V = Go(m1 | (1 << pv), m2 | ((1 - ck) << pv), U[0] ^ (1 << pv), U[1] ^ (1 << pv));
		res.push_back(U[0]);
		for (auto &t : V)res.push_back(t);
		for (i = 1; i < U.size(); i++)res.push_back(U[i]);
	}
	return res;
}
int main() {
	int i, a, b, s = 0;
	scanf("%d%d%d", &n,&a,&b);
	for (i = 0; i < 20; i++) {
		if (((a^b) >> i) & 1)s^=1;
	}
	if (!s) {
		puts("NO");
		return 0;
	}
	puts("YES");
	vector<int>res = Go(0, 0, a, b);
	for (auto &t : res)printf("%d ", t);
}

Measured memory_bytes: 1628
#include<iostream>
#include<vector>

using namespace std;

template<class T> inline bool chmin(T& a, T b){
  if(a > b){
    a = b;
    return true;
  }
  return false;
}

template<class T> inline bool chmax(T& a, T b){
  if(a < b){
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;

int main(void){
  int N, K;
  
  cin >> N >> K;
  
  int h[N];
  
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  
  vector<long long> DP(100010, INF);
  
  DP[0] = 0;
  
  for(int i = 1; i < N; i++){
    for(int j = 1; j <= K; j++){
      if(i < j) break;
      chmin(DP[i], DP[i-j] + abs(h[i] - h[i-j]) );
    }
  }
  
  cout << DP[N-1] << endl;
  return 0;
}



Measured memory_bytes: 1408
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
double a,b,x,s,now;
int main()
{
  scanf("%lf%lf%lf",&a,&b,&x);
  double piee=2*acos(0);
  s=x/a;
  if (s<=a*b/2) 
  {
  	//cout<<s<<endl;
    now=atan(b*b/(2.0*s));
    now=now*180/piee;
    printf("%.8lf\n",now);
  }
  else
  {
  	now=2.0*s/a;
  	now=2.0*b-now;
  	now=now/a;
  	now=atan(now)*180/piee;
  	printf("%.8lf\n",now);
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<(int) (n);i++)
using namespace std;
int main() {
	int h, n,cnt=0;
	cin >> h >> n;
	rep(i, n) {
		int a;
		cin >> a;
		cnt += a;
	}

	if (cnt >= h)cout << "Yes";
	else cout << "No";
}

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

int main() {
    long long a, b, c, d, lcm;
    cin >> a >> b >> c >> d;
    lcm = c / __gcd(c, d) * d;
    a--;
    cout << b - a - (b / c + b / d - b /lcm) + (a / c + a / d - a /lcm);
    return 0;
}


Measured memory_bytes: 256