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

#define REP(i,n) for(int i = 0; i < n; i++)
#define PER(i,n) for(int i = n-1; i >= 0; i--)
#define FOR(i,l,r) for(int i = l; i <= r; i++)
#define ROF(i,l,r) for(int i = r; i >= l; i--)
#define DEBUG(x) cout << #x << "=" << x << endl;
#define SHOW1(A,n) { REP(i,n) cout<<A[i]<<(i==n-1?'\n':' '); }
#define SHOW2(A,m,n) { REP(j,m) SHOW1(A[j],n) }
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)((x).size())
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int INF = 0x3f3f3f3f, MOD = 998244353;
const double PI = acos(-1), EPS = 1e-15;
const int MAXN = 1e3+9, MAXM = 2e5+9;

int m,n,vis[MAXN][MAXN];
char s[MAXN][MAXN];
const int r[]={0,0,1,-1};
const int c[]={1,-1,0,0};
#define vld(i,j) (0<=i&&i<m&&0<=j&&j<n)
struct node { int x,y,t; };
int bfs()
{
    memset(vis,0,sizeof(vis));
    queue<node> Q;
    REP(i,m)REP(j,n) if (s[i][j]=='#') Q.push({i,j,0}), vis[i][j]=1;
    int ans=0;
    while (!Q.empty()) {
        node now=Q.front(); Q.pop();
        int x=now.x,y=now.y,t=now.t;
        ans=max(ans,t);
        REP(i,4) {
            int xx=x+r[i], yy=y+c[i];
            if (vld(xx,yy) && !vis[xx][yy]) {
                vis[xx][yy]=1;
                Q.push({xx,yy,t+1});
            }
        }
    }
    return ans;
}

int main()
{
#ifdef LOCAL
    //freopen("i.txt", "r", stdin);
    //freopen("o.txt", "w", stdout);
#endif //LOCAL

    while (cin>>m>>n) {
        REP(i,m) scanf("%s", s[i]);
        cout<<bfs()<<endl;
    }

    return 0;
}































Measured memory_bytes: 17296
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    """
    エラトステネスの篩。√N以下の数に対して2から順にその数の倍数を消していく。
    計算量は「調和級数」になるのがミソ。具体的には
        N/2 + N/3 + N/5 + ... + N/(√N) = N * (1/2 + 1/3 + 1/5 + ... + 1/√N)
                                       = N * loglog(√N) (素数の逆数和の発散スピードがこれ)
                                       = N(loglogN - log2)
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        return []
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit < p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def main():
    primes = get_sieve_of_eratosthenes(100000)
    like = [0] * 10**5
    for i in range(3, 10**5):
        if i in primes and (i + 1) // 2 in primes:
            like[i] = 1
    like = list(accumulate(like))

    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        if l < 3: l = 3
        if r < 3:
            print(0)
            continue
        print(like[r] - like[l - 1])



if __name__ == "__main__":
    main()

    

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

int main(){
        int n;
        string s;
        cin>>n;
        cin>>s;
        int dep=0, addl=0, addr=0;
        for(int i=0; i<n; i++){
                if(s[i]=='(') dep++;
                else if(s[i]==')'){
                        if(dep==0) addl++;
                        else dep--;
                }
        }
        addr=dep;
        for(int i=0; i<addl; i++) cout<<"(";
        cout<<s;
        for(int i=0; i<addr; i++) cout<<")";
        cout<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<climits>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int min_count=INT_MAX;
    for(int i=0;i<=s.size()-t.size();i++)
    {
        int count=0;
        for(int j=0;j<t.size();j++)
        {
            if(s[i+j]!=t[j]){
                count++;
            }
        }
        if(min_count>count){
            min_count=count;
        }
    }
    cout<<min_count;
}

Measured memory_bytes: 3596
n, p, q = gets.to_i, gets.split.map(&:to_i), gets.split.map(&:to_i)
fact = 1.upto(n).inject(&:*)
p, q = p.map{|i| i-1}, q.map{|i| i-1}
ap, aq = 1, 1
n.times do |i|
  fact /= n-i
  ap += fact * p[i]
  aq += fact * q[i]
  (i + 1).upto(n-1) do |i2|
    p[i2] -= 1 if p[i] < p[i2]
    q[i2] -= 1 if q[i] < q[i2]
  end
end
puts (ap - aq).abs

Measured memory_bytes: 1788
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	string s;
	cin >> s;
	int y = 700;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') y += 100;
	}
	cout << y;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void insert(int A[],int N);
void show(int A[],int N);

  void insert(int A[], int N) {
  int j;
  int i;
  int tr;
  int f;
    for (int  i = 1; i < N; i++) {
      j=i-1;
      f=A[i];
      while(0<=j && A[j]>f){
          j--; //where to put f
        }
      for(int a=i-1;a>=j;a--){
          A[a+1]=A[a];
      }

        A[j+1]=f;
        show(A,N);
      }
    }

  void show(int A[],int N){
    for (int i = 0; i < N; i++) {
        printf("%d", A[i]);
        if(i!=N-1)printf(" ");
    }
    printf("\n");
  }
  int main(){
  int A[100];
  int N;
  scanf("%d",&N);
  for (int  i = 0; i < N; i++) scanf("%d",&A[i] );
  show(A,N);
  insert(A,N);

}


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

int main() {
  int N;
  cin >>N;
  if ( N == 1 )
    cout << 0 << endl;
  else{
  int COUNT = 0;
  int KARI = 0;
  vector<int> H(N);
    cin >> H.at(0);
    for (int i = 1; i < N; i++) {
    cin >> H.at(i);
      if ( H.at(i) <= H.at(i-1) ){
        COUNT++;
        }
      else if ( COUNT > KARI ){
        KARI = COUNT;
         COUNT = 0;
        }
      else{
         COUNT = 0;
         }
    }
 cout << ((COUNT > KARI) ? COUNT : KARI) << endl;
  }
 }

Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var S = ReadLine();
            WriteLine(String.Join("", S.Select(c => 'x')));
        }
    }
}


Measured memory_bytes: 18464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
/*using P = pair<int, int>;*/
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;


int main(){
    ll x, a, b; cin >> x;
    b = 0;
    while(1){
        ll current_num = x + b*b*b*b*b;
        ll current_num_m = x - b*b*b*b*b;
        a = 0;
        while(a*a*a*a*a<current_num){
            a++;
        }
        if(a*a*a*a*a==current_num){
            cout << a << " " << b << endl;
            break;
        }
        a = 0;
        while(a*a*a*a*a<current_num_m){
            a++;
        }
        if(a*a*a*a*a==current_num_m){
            cout << a << " " << b * (-1) << endl;
            break;
        }
        b++;
    }
    return 0;
}

Measured memory_bytes: 3592
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
read = sys.stdin.read

def main():
    N = int(readline())
    graph = [[] for _ in range(N + 1)]

    for i in readlines():
        u, v, w = map(int, i.split())
        graph[u].append((v, w))
        graph[v].append((u, w))

    stack = [1]
    parent = [0] * (N + 1)
    color = [0] * (N + 1)

    while stack:
        here = stack.pop()
        for x, w in graph[here]:
            if x == parent[here]:
                continue
            parent[x] = here
            color[x] = color[here] ^ (w % 2)
            stack.append(x)

    for i in color[1:]:
        print(i)


if __name__ == '__main__':
    main()

Measured memory_bytes: 44972
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;


int main()
{
    FAST;
 
    ll n;
    cin>>n;
    
    ll ans=0;
    for(int i=1; i<=n; i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            ans+=i;
        }
    }
    
    cout<<ans;
    
}

Measured memory_bytes: 3652
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		String stones = in.next();
		in.close();
		
		// i = [i-1] is left, [i] is right
		int[] left = new int[N+1];	// left is white(.)
		
		// i = [i-1] is left, [i] is right
		int[] right = new int[N+1];	// right is black(#)
		
		left[0] = 0;
		for (int i=0; i<N; i++) {
			if (stones.charAt(i) == '.') {
				left[i+1] = left[i];
			} else {
				left[i+1] = left[i] + 1;
			}
		}
		right[N] = 0;
		for (int i=N-1; i>=0; i--) {
			if (stones.charAt(i) == '#') {
				right[i] = right[i+1];
			} else {
				right[i] = right[i+1] + 1;
			}
		}
		
		int min = Integer.MAX_VALUE;
		for (int i=0; i<N+1; i++) {
			int val = left[i] + right[i];
			if (val < min) {
				min = val;
			}
		}
		
		System.out.println(min);
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
}


Measured memory_bytes: 28872
#include<stdio.h>
#include<stdlib.h>
int main()
{
	long long x,ans,l=0,r=200000,mid;
	scanf("%lld",&x);
	x=x>=0?x:-x; //正负等价
	//∑ans>=x的最小ans即为答案 即ans(ans+1)/2=x
	while(l<=r){ //数据量大二分查找
		mid=(l+r)/2;
		if(mid*(mid+1)/2>=x) r=mid-1;
		else l=mid+1;
	}
	ans=l;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 998244353;


ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

void no() {
	cout << 0 << "\n";
	exit(0);
}

map<pair<int, int>, int> mm;
const int MAXN = 120000;

ll n, m;
vector<int> go[MAXN * 2];

int dd[MAXN * 2][3];
ll dp[8];
ll dp2[2];

int pc[10];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	ll gg = n * n - n - 2 * (n - 1) - 2 * (n - 2);
	gg /= 2;
	for (int i = 0; i < 2 * n; ++i)
		for (int j = 0; j < 3; ++j)
			dd[i][j] = -1;
	for (int i = 0; i < m; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		--a, --b;
		if (mm.count({a, b})) {
			if (mm[{a, b}] != c)
				no();
			continue;
		}
		if (abs(a - b) > 2) {
			--gg;
			mm[{a, b}] = c;
			mm[{b, a}] = c;
		}
		else {
			if (abs(a - b) <= 1) {
				go[a + b].push_back(c);
			}
			if (abs(a - b) % 2 == 0) {
				dd[(a + b) / 2][1 + (a - b) / 2] = c;
			}
		}
	}
	for (int i = 1; i < n - 1; ++i) {
		int cc = 0;
		for (int j = 0; j < 3; ++j)
			if (dd[i][j] != -1)
				++cc;
		if (cc == 0) {
			++gg;
		}
		else if (cc == 1) {
			if (dd[i][1] != -1)
				++gg;
		}
		else if (cc == 2) {
			if (dd[i][1] == -1) {
				dd[i][1] = dd[i][0] ^ dd[i][2];
				go[i * 2].push_back(dd[i][1]);
			}
		}
		else {
			if ((dd[i][0] ^ dd[i][1] ^ dd[i][2]) != 0)
				no();
		}
	}
	for (int i = 0; i < n; ++i)
		if (go[2 * i].empty())
			go[2 * i].push_back(-1);
	for (int i = 0; i < n - 1; ++i)
		while (go[2 * i + 1].size() < 2)
			go[2 * i + 1].push_back(-1);
	array<int, 3> a = {go[0][0], go[1][0], go[1][1]};
	for (int i = 0; i < 8; ++i) {
		int fl = 0;
		for (int j = 0; j < 3; ++j) {
			if (a[j] != -1 && a[j] != ((i >> j) & 1))
				fl = 1;
		}
		if (!fl)
			dp[i] = 1;
		else
			dp[i] = 0;
	}
	for (int i = 0; i < 8; ++i)
		pc[i] = __builtin_popcount(i) % 2;
	for (int i = 1; i < n; ++i) {
		memset(dp2, 0, sizeof(dp2));
		for (int j = 0; j < 8; ++j) {
			int cur = pc[j];
			if (go[2 * i][0] != -1 && go[2 * i][0] != cur)
				continue;
			dp2[cur] = (dp2[cur] + dp[j]) % MOD;
		}
		if (i == n - 1)
			break;
		memset(dp, 0, sizeof(dp));
		array<int, 3> a = {-1, go[2 * i + 1][0], go[2 * i + 1][1]};
		for (int j = 0; j < 2; ++j) {
			a[0] = j;
			for (int i = 0; i < 8; ++i) {
				int fl = 0;
				for (int j = 0; j < 3; ++j) {
					if (a[j] != -1 && a[j] != ((i >> j) & 1))
						fl = 1;
				}
				if (!fl)
					dp[i] = dp2[j];
			}
		}
	}
	cout << (dp2[0] + dp2[1]) * pw(2, gg) % MOD << "\n";
	return 0;
}




Measured memory_bytes: 21248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); int K = sc.nextInt();
		String S = sc.next();
		sc.close();
		char[] ch = S.toCharArray();
		int cnt = 0;
		for(int i = 1;i < N;i++) {
			if(ch[i]==ch[i-1]) {
				cnt++;
			}
		}
		System.out.println(Math.min(cnt + K * 2,N - 1));
	}
}

Measured memory_bytes: 27860
#include<stdio.h>
#include<string.h>
int main(void)
{
    int n,i,a;
    char s[100],p[100] = "0",q[100] = "0";
    scanf("%d %s",&n,s);
    for(i = 1 ; i <= n / 2 ; i++)
    {
        
        
        strncpy(p,s,i);
        strncpy(q,s,i);
        
        p[i] = '\0';
        q[i] = '\0';
        strcat(p,q);
        
        if(strcmp(p,s) == 0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 1668
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace NikkeiPGKing
{
    class Program
    {
        static void Main(string[] args)
        {
            Problem1.Problem1Read();
        }
    }
    public sealed class Problem1
    {
        public static void Problem1Read()
        {
            string[] input = Console.ReadLine().Split(' ');
            var res = Problem1SolveTuple(int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]));
            Console.WriteLine("{0} {1}", res.Item1, res.Item2);
        }

        public static Tuple<int, int> Problem1SolveTuple(int n, int a, int b)
        {

            return new Tuple<int, int>(
                Math.Min(a, b),
                Math.Max(a + b - n, 0)
            );
        }
    }
}


Measured memory_bytes: 13140
import sys
input = sys.stdin.readline

N = int(input())

a, b, c, d = 0, 0, 0, 0

for _ in range(N):
    S = input().rstrip()
    if S == "AC": a += 1
    elif S == "WA": b += 1
    elif S == "TLE": c += 1
    else: d += 1

print("AC x", a)
print("WA x", b)
print("TLE x", c)
print("RE x", d)

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

int main(){
  int n,m,q;
  cin >> n >> m >> q;
  int a[55], b[55], c[55], d[55];
  rep(i,q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  vector<int> vec(n+m-1,1);
  rep(i,m-1)vec[i]=0;
  int ans = 0;
  do{
    int zero_cnt=1;
    int score = 0;
    vector<int> A;
    rep(i,n+m-1){
      if(vec[i]==0)zero_cnt++;
      else A.push_back(zero_cnt);
    }
    rep(i,q){
      if(A[b[i]]-A[a[i]]==c[i])score+=d[i];
    }
    ans = max(ans,score);
  }while(next_permutation(vec.begin(),vec.end()));

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


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int n,k; cin >> n >> k;
    int h[n]; for(int i=0; i<n; i++) cin >> h[i];
    int dp[n+k]; for(int i=0; i<n; i++) dp[i] = 1e9;
    dp[0] = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<k; j++){
            dp[i+j+1] = min(dp[i]+abs(h[i]-h[i+j+1]),dp[i+j+1]);
        }
    }
    cout << dp[n-1] << endl; 
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] HN = br.readLine().split(" ") ; 
		int H = Integer.parseInt(HN[0]);
		int N = Integer.parseInt(HN[1]);
		
		String[] IN =br.readLine().split(" ") ; 
		int sum = 0;
		for(int n=0; n<N; n++) {
			sum += Integer.parseInt(IN[n]);
		}
		
		String ans = "Yes";
		if(sum<H) {
			ans = "No";
		}
		
		System.out.println(ans);	
		
	}
}

Measured memory_bytes: 44488
#include <iostream>
using namespace std;
int a[200000] = {};
int b[200001] = {};
int p[200000] = {};

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

    int i = 1, j = 0, x = b[0] ^ b[1];
    while (i < n){
        if ((b[i] ^ b[j]) == x){
            p[i] = j+1;
            i++;
            j++;
        }
        else{
            j--;
            if (j) j = p[j];
            else x = b[i] ^ b[0];
        }
    }

    i = 0; j = 0; x = a[0] ^ b[0];
    while (i < 2*n - 1){
        if ((a[i % n] ^ b[j]) == x){
            i++;
            j++;
            if (j == n) cout << i - n << ' ' << x << '\n';
        }
        else{
            j--;
            if (j){
                x ^= b[j] ^ b[p[j] - 1];
                j = p[j];
            }
            else x = a[i % n] ^ b[0];
        }
    }
}


Measured memory_bytes: 5760
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

   ll res = 0;
   for(ll i=1; i<1000000; i++){
       double d = n / (double)i - 1;
       if(d < 2) break;
       if(n % i == 0 && d > i) res += d;
   }

   cout << res << ln; 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	if (s[0] == '9' || s[1] == '9') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int maxn=0;
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            if(maxn<abs(a[i]-a[j])){
                maxn=abs(a[i]-a[j]);
            }
        }
    }
    cout<<maxn<<endl;
    return 0;
}


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


int main()
{
   int n,i,j,k;
   cin>>n>>k;
   int a[n+1];
   int h[n+1];
   
   for(i=0;i<n;i++)
   {
   	cin>>a[i];
   	h[i]=INT_MAX;
   }
   
   h[0]=0;

   for(i=0;i<n;i++)
   {
   	 for(j=1;j<=k;j++)
   	 {
   	 	if(i+j<n)
   	 	{
   	 		h[i+j]=min(h[i+j],h[i]+abs(a[i]-a[i+j]));
   	 	}
   	 }
   }
    
    cout<<h[n-1]<<"\n";
 	return 0;
}

Measured memory_bytes: 1024
import math
l=[int(input()) for i in range(5)]
ans=min(l[0]+math.ceil(l[1]/10)*10+math.ceil(l[2]/10)*10+math.ceil(l[3]/10)*10+math.ceil(l[4]/10)*10,
math.ceil(l[0]/10)*10+l[1]+math.ceil(l[2]/10)*10+math.ceil(l[3]/10)*10+math.ceil(l[4]/10)*10,
math.ceil(l[0]/10)*10+math.ceil(l[1]/10)*10+l[2]+math.ceil(l[3]/10)*10+math.ceil(l[4]/10)*10,
math.ceil(l[0]/10)*10+math.ceil(l[1]/10)*10+math.ceil(l[2]/10)*10+l[3]+math.ceil(l[4]/10)*10,
math.ceil(l[0]/10)*10+math.ceil(l[1]/10)*10+math.ceil(l[2]/10)*10+math.ceil(l[3]/10)*10+l[4])
print(ans)

Measured memory_bytes: 3188
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    F = [''.join(readstrs()) for _ in range(N)]
    P = [list(readnums()) for _ in range(N)]
    ans = -(10 ** 9)
    for i in range(1, 1024):
        val = 0
        for j, f in enumerate(F):
            c = bin(i & int(f, 2))[2:]
            v = sum(map(int, c))
            val += P[j][v]

        ans = max(ans, val)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<set>
#define sqr(x) (x)*(x)
using namespace std;
string st;
int n,m,i,j,mi=1e9;
int main()
{
	cin>>st;
	if (st=="zyxwvutsrqponmlkjihgfedcba")
	{
		cout<<-1;
		return 0;
	}
	if (st.size()==26)
	{
		for (i=24;i>-1;i--)
		{
			mi=1e9;
			for (j=i+1;j<=25;j++)
			{
				if (st[i]<st[j]) mi=min(mi,(int)st[j]);
			}
			if (mi<1000)
			{
				st[i]=mi;
				st.erase(i+1);
				cout<<st;
				return 0;
			}
		}
	}
	else
	{
		set<char> s;
		for (i='a';i<='z';i++) s.insert(i);
		for (i=0;i<st.size();i++) s.erase(st[i]);
		cout<<st<<*s.begin();
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[55][55],b[55][55];
int main()
{
    int n,m,flag1=0,flag2=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",a[i]);
    for(int i=0;i<m;i++)
    scanf("%s",b[i]);
    for(int i=0;i<=n-m;i++)
        for(int j=0;j<=n-m;j++)
    {
        flag1=0;
        for(int k=0;k<m;k++)
                for(int l=0;l<m;l++)
            {
                if(a[i+k][j+l]!=b[k][l]) {flag1=1;}
            }

        if(flag1==0)
        {
            flag2=1;
            break;
        }
    }
    if(flag2) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

int solve() {
    string s, t;
    cin >> s >> t;
    int n = sz(s), m = sz(t);
    int ans = 1e9;
    rep(i, 0, n - m) {
        int cur = 0;
        rep(j, 0, m - 1) {
            cur += s[i + j] != t[j];
        }
        ans = min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void)
{
  int n, k;
  scanf("%d %d", &n, &k);
  char s[n + 1];
  scanf("%s", s);
  
  for (int i = 0; i < k; i++){
    int j = 1;
    while (j < n){
      if (s[0] == s[j]) j++;
      else break;
    }
    if (j == n){
      printf("%d\n", n - 1);
      return 0;
    }
    
    int l = j + 1;
    while (l < n){
      if (s[j] == s[l]) l++;
      else break;
    }
    
    int len = l - j;
    for (int m = 1; m <= len; m++){
      s[j + m - 1] = s[j - 1];
    }
  }
  
  int sum = 0;
  for (int i = 1; i < n; i++){
    if (s[i] == s[i - 1]) sum++;
  }
  
  printf("%d", sum);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

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

    rep(i, s.size()) {
        s[i] = ((s[i] - 'A') + n) % 26 + 'A';
    }
    cout << s << endl;
}


Measured memory_bytes: 888
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List as L

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [n, x] <- map read . words <$> getLine
  m <- replicateM n getInts
  printf "%d" $ n + slv x (concat m)

slv :: Int -> [Int] -> Int
slv x m = mNum
  where xMod = x - sum m
        mMin = minimum m
        mNum = xMod `div` mMin


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

int n;
int a, b;

int main()
{
  while((cin >> n) && n){
    int res[2] = {0};
    while(n--){
      cin >> a >> b;

      if(a >  b){ res[0] += a + b;  continue; }
      if(a <  b){ res[1] += a + b;  continue; }
      res[0] += a;
      res[1] += b;
    }

    cout << res[0] << " " << res[1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
using namespace std;
const int maxn = 1e6 + 10;
int vis[maxn];

int main()
{
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	#endif
	int mod, ans, x = 0;
	scanf("%d", &mod);
	for (ans = 1; ; ++ans) {
		x = (x * 10 + 7) % mod;
		if (!x) break;
		if (vis[x]) {
			ans = -1;
			break;
		}
		vis[x] = 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 7628
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N, M = readmap()
X = readlist()

if N >= M:
    print(0)
    quit()

X.sort()
diff = [X[i+1] - X[i] for i in range(M-1)]
diff.sort()
ans = sum(diff[:M-N])

print(ans)

Measured memory_bytes: 13960
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
print('U' * dy + 'R' * dx + 'D' * dy + 'L' * dx
      + 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
      + 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  while(1){
	int x,y,s;
	cin >> x >> y >> s;
	if(x==0&&y==0&&s==0) break;

	int now = 0;
	int mae;
	int ato;

	REP(i,s){
	  REP(j,s){
		if(i==0||j==0) continue;
		mae = (i*(100+x))/100+(j*(100+x))/100;
		ato = (i*(100+y))/100+(j*(100+y))/100;

		if(mae==s && ato > now) now = ato;
		  //		  cout << i <<" " << j <<endl;}
	  }
	}
	cout << now << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[200005], sum[200005];

P calc(llint l, llint r)
{
	llint s = sum[r]-sum[l-1];
	
	llint ub = r, lb = l-1, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(sum[mid]-sum[l-1] >= s/2) ub = mid;
		else lb = mid;
	}
	P ret = P(-inf, inf);
	if(ub < r){
		llint a = s - (sum[ub]-sum[l-1]), b = sum[ub]-sum[l-1];
		ret.first = max(ret.first, min(a, b));
		ret.second = min(ret.second, max(a, b));
	}
	if(lb >= l){
		llint a = s - (sum[lb]-sum[l-1]), b = sum[lb]-sum[l-1];
		ret.second = min(ret.second, max(a, b));
		ret.first = max(ret.first, min(a, b));
	}
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	
	llint ans = inf;
	for(int i = 3; i <= n-1; i++){
		P res = calc(1, i-1), res2 = calc(i, n);
		ans = min(ans, max(res.second, res2.second) - min(res.first, res2.first));
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3328
/*
Template for vjudge.net

	Author: Iqbal Hossain Rasel
	CodeForces: The_Silent_Man
	AtCoder   : IHR57
	TopCoder  : IHR57

*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 3005
using namespace std;

typedef long long ll;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

ll dp[MAX][MAX][2];
ll arr[MAX];
int n;

ll solve(int i, int j, int x)
{
    if(i > j)
        return 0;
    if(dp[i][j][x] != -1)
        return dp[i][j][x];
    ll ret = 0;
    if(x == 0){
        ret = arr[i] + solve(i + 1, j, !x);
        ret = max(ret, arr[j] + solve(i, j - 1, !x));
    }
    else{
        ret = solve(i + 1, j, !x) - arr[i];
        ret = min(ret, solve(i, j - 1, !x) - arr[j]);
    }

    return dp[i][j][x] = ret;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif
    cin>>n;

    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    memset(dp, -1, sizeof(dp));
    ll result = solve(0, n - 1, 0);

    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int A[100000];
LL light(int i, int j) {
  if (A[i] > 0) return A[j];
  if (A[j] < 0) return -A[i];
  return min(2 * -A[i] + A[j], -A[i] + 2 * A[j]);
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, k; cin >> n >> k;
  --k;
  LL ans = 1e18;
  for (int i = 0; i < n; ++i) cin >> A[i];
  for (int i = 0; i + k < n; ++i) ans = min(light(i, i + k), ans);
  cout << ans << '\n';
}


Measured memory_bytes: 640
def main():
    n = int(input())
    c = list(input())
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
        else:
            w += 1

    count = 0
    for i in range(r):
        if c[i] == "W":
            count += 1
    print(count)


if __name__ == '__main__':
    main()


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

int main(void){
    // Your code here!
    int n,m;
    cin>>n>>m;
    vector<int> s(m);
    vector<int> c(m);
    rep(i,m) {cin>>s[i]>>c[i]; s[i]--;}
    int ans=-1;
    if(m>0){
    for(int j=0;j<1000;j++){
        int x=0;
        string t=to_string(j);
        rep(i,m){
            string y=to_string(c[i]);
        if(t.size()==n&&t[s[i]]==y[0]){
            x++;
        }
        }
        if(x==m){ ans=j; break;}
    }
    }
    else{
        for(int i=0;i<1000;i++){
            string t=to_string(i);
            if(t.size()==n){
                ans=i;
                break;
            }
            
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
leftest=0
cnt=1
for right in range(1,n):
    if a[leftest]>a[right-1]:
        if a[right-1]<a[right]:
            cnt+=1
            leftest=right
    elif a[leftest]<a[right-1]:
        if a[right-1]>a[right]:
            cnt+=1
            leftest=right
print(cnt)

Measured memory_bytes: 15120
def dfs(i,s):
    if i==(n-1):
        return(sum(map(int,s.split('+'))))
    return(dfs(i+1,s+S[i+1])+dfs(i+1,s+'+'+S[i+1]))


S=input()
n=len(S)
ans=dfs(0,S[0])
print(ans)

Measured memory_bytes: 3060
printNum::(Bool,Int)->IO()
printNum (a,b) = putStrLn $ take b $ array a
	where
	array a
		|a==True = cycle['#','.']
		|a==False = cycle['.','#']

printRec::(Int,Int)->IO ()
printRec (a,b) = sequence_ $ (\x->x++[putStrLn ""]) $ map printNum $ map (\x->(x`mod`2==1,b)) $ take a [1,2..]



function::String->IO ()
function x=mapM_ printRec $ takeWhile(/=(0,0))$map (\[x,y]->(read x::Int,read y::Int)) $ map words $ lines x

main = getContents >>= function

Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b,c;
    cin >>a>>b>>c;
    
    if (a+b < c)cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return 0;
}



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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll blue = a * (n / (a + b));
  blue += min(a, n % (a + b));
  cout << blue << endl;
}

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

  solve();
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int n;
  while(cin>>n,n) {
    int hoge[2*n];
    UnionFind uf(2*n);
    map<string,int> id;
    int cnt = 0;
    bool f = 0;
    REP(i,n) {
      int tmp;
      string tmps, s1,s2,xx;
      cin>>tmp>>s1>>tmps>>xx>>s2;
      int x = atoi(xx.substr(3).c_str());
    
      if (id.count(s1)==0 && id.count(s2)==0) {
        id[s1] = cnt++;
        id[s2] = cnt++;
        hoge[id[s1]] = 0;
        hoge[id[s2]] = -x;
      } else if (id.count(s1)==0) {
        id[s1] = cnt++;
        hoge[id[s1]] = hoge[id[s2]] + x;
      } else if (id.count(s2)==0) {
        id[s2] = cnt++;
        hoge[id[s2]] = hoge[id[s1]] - x;
      } else {
        if (uf.findSet(id[s1], id[s2])) {
          if (hoge[id[s1]] != hoge[id[s2]] + x) {
            f = 1;
          }
        } else {
          int tmp = hoge[id[s1]] - hoge[id[s2]];
          REP(j, cnt) {
            if (uf.findSet(id[s2], j)) {
              hoge[j] += tmp - x;
            }
          }
        }
      }
      uf.unionSet(id[s1], id[s2]);
      // printf("%d,%d\n", uf.root(id[s1]), uf.root(id[s2]));
      // FOR(it, id) {
      //   cout << it->first << " " << it->second << " " << hoge[it->second] << endl;
      // }
      // cout << endl;
    }
    if(f)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
}

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

using namespace std;

const int MX_SZ = 1e+5 + 42;

bool is_similar(int x) {
    if (x == 1) {
        return false;
    }
    for (int i = 2; i * i <= x; ++i) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    vector<int> pref(MX_SZ, 0);
    for (int i = 1; i < MX_SZ; ++i) {
        pref[i] = pref[i - 1] + (is_similar(i) and is_similar((i + 1) / 2));
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        cout << pref[r] - pref[l - 1] << endl;
    }
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
 char S[]="ACGT";
 char b;
  char X[3];
  scanf("%s\n",&b);
  X[0]=b;
  if(X[0]==S[0])
    puts("T");
  else if(X[0]==S[1])
    puts("G");
  else if(X[0]==S[2])
    puts("C");
  else if(X[0]==S[3])
    puts("A");
  return 0;
}

Measured memory_bytes: 128
import math
A, B, H, M = map(int, input().split())
a = 0.5 * (60 * H + M)
b = 6 * M
if b >= a:
    ang = min(b - a, 360 - (b - a))
else:
    ang = min(a - b, 360 - (a - b))
l = (A ** 2 + B ** 2) - (2 * A * B * math.cos(math.radians(ang)))
print(math.sqrt(l))

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

int main() {
    ll n,m;
    std::cin >> n>>m;
    
    vector<vector<ll>> edges(n);
    
    for (int i = 0; i < m; i++) {
        ll a,b;
        std::cin >> a>>b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    
    vector<bool> used(n,false);
    
    ll s = 0;
    ll t = edges[0][0];
    ll it=t;
    used[s] = used[t] = true;
    vector<ll> sv,tv;
    while(true){
        bool ok = true;
        for (auto e : edges[s]) {
            if(!used[e]){
                used[e]=true;
                s = e;
                sv.push_back(e);
                ok = false;
                break;
            }
        }
        if(ok)break;
    }
    while(true){
        bool ok = true;
        for (auto e : edges[t]) {
            if(!used[e]){
                used[e]=true;
                t = e;
                tv.push_back(e);
                ok = false;
                break;
            }
        }
        if(ok)break;
    }
    std::cout << sv.size()+tv.size()+2 << std::endl;
    for (int i = 0; i < sv.size(); i++) {
        std::cout << sv[sv.size()-1-i]+1<<" ";
    }
    std::cout <<1<<" "<<it+1<<" ";
    for (int i = 0; i < tv.size(); i++) {
        std::cout << tv[i]+1<<" ";
    }
    std::cout << std::endl;
}


Measured memory_bytes: 7156
N=gets.to_i;puts N<3?-1:N<4?'a..
a..
.bb':((0..N-4)%4).map{|j|([f=%w(aabc ddbc efgg efhh),%w(affgg axe bxe b.dyy ccdhh),%w(aabc ddbc ..eefg ..hhfg ij..kk ij..ll),%w(ag..g ag..g b.ss.ss bg..g cg..g c.ss.ss .ppqqrr)][N-j-4]||f).map{(?.*j+_1+?.*N)[0,N]}}

Measured memory_bytes: 17144
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	int r = 0;
	ll sum = 0;
	int ans = inf;
	bool b = false;
	for (int l = 0; l < n; l++)
	{
		while (r < n && sum + a.at(r) < s)
		{
			sum += a.at(r);
			r++;
		}

		if (r < n)
		{
			b = true;
			ans = min(ans, r - l + 1);
		}

		if (l == r)
		{
			r++;
		}
		else
		{
			sum -= a.at(l);
		}
	}

	if (!b)
	{
		ans = 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3140
#include<cstdio>//AT2361
#include<cstring>
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=1e5+5;

int n;

long long a[3*N],ans;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=3*n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+3*n+1);
    for(int i=3*n-1;i>n;i-=2){
        ans+=a[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(m);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
	vec[i].resize(k);
	for (int j = 0; j < k; ++j) {
	  cin >> vec[i][j];
	  --vec[i][j];
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; ++i) cin >> p[i];
  
  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    bool frag = true;
	for (int j = 0; j < m; ++j) {
	  int c = 0;
	  for (int id : vec[j]) {
	    if ((i >> id) & 1) ++c;
	  }
	  c %= 2;
	  if (c != p[j]) {
	    frag = false;
	  }
    }
	if (frag) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define ull unsigned long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pul pair<ull,LL> 
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
const int mod=998244353;
template<typename T> void chkmin(T &x,T y) {if(y<x) x=y;}
template<typename T> void chkmax(T &x,T y) {if(y>x) x=y;}
template<typename T> void upd(T &x,T y) {if((x+=y)>=mod) x-=mod;}
int n,K,sl,fh,ans,a[3010],f[3010];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();K=rd();
	for(int i=1;i<=n;++i) a[i]=rd();
	for(int i=1;i<=n;++i)
		if(a[i]<=K)
		{
			ans=(ans+i*(n-i+1)*(a[i]==K)+1ll*f[K-a[i]]*(n-i+1))%mod;
			for(int j=K;j>=a[i];--j) upd(f[j],f[j-a[i]]);
			upd(f[a[i]],i);
		}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n,k; cin>>n>>k;
    vector<int> v(n);
    rep(i, k){
        int d; cin >> d;
        rep(j, d){
            int a; cin >> a; a--;
            v[a]++;
        }
    }
    int ans=0;
    rep(i, n){
        if(v[i]==0) ans++;
    }
    out(ans);
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
using namespace std;
char a[1005][1005];
int dp[1005][1005];
int ans;

const int mod = (int)1e9 + 7;

main()
{
	int n , m;
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			cin >> a[i][j];
		}
	}
	dp[1][1] = 1;
	
	for(int i = 2; i <= n; i++){
		dp[i][1] = dp[i-1][1];
		if(a[i][1] == '#')dp[i][1] = 0;
	}
	for(int i = 2; i <= m; i++){
		dp[1][i] = dp[1][i-1];
		if(a[1][i] == '#')dp[1][i] = 0;
	}
	
	for(int i = 2; i <= n; i++)
	{
		for(int j = 2; j <= m; j++)
		{
			if( a[i][j] != '#' )
			dp[i][j] = dp[i-1][j] + dp[i][j-1] , dp[i][j] %= mod;
		}
	}
	
	//for(int i = 0; i <= n; i++)
	//{
		//for(int j = 0; j <= m; j++)
			//cout << dp[i][j] << " ";
		//cout << endl;
	//}
	
	cout << dp[n][m] % mod << endl;
	
}


Measured memory_bytes: 9088
s = gets.chomp
if s =~ /^.*keyence$/ ||
    s =~ /^k.*eyence$/ ||
    s =~ /^ke.*yence$/ ||
    s =~ /^key.*ence$/ ||
    s =~ /^keye.*nce$/ ||
    s =~ /^keyen.*ce$/ ||
    s =~ /^keyenc.*e$/ ||
    s =~ /^keyence.*$/
    puts "YES"
else
    puts "NO"
end


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;
const int MIN = 20;

struct Query
{
	int x;
	int d;
	int c;

	Query(int x, int d, int c)
	{
		this->x = x;
		this->d = d;
		this->c = c;
	}

	Query(){}
} Q[MAX];

VI g[MAX];

bool U[MAX][MIN];
int C[MAX];

void dfs(int x, int d, int c)
{
	if (U[x][d]) return;
	if (C[x] == -1) C[x] = c;
	U[x][d] = 1;

	if (d == 0) return;

	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		dfs(to, d-1, c);
	}
}

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

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		g[x].PB(y);
		g[y].PB(x);
	}

	int q;
	scanf("%d", &q);
	FOR (i, 0, q)
	{
		int x, d, c;
		scanf("%d%d%d", &x, &d, &c);
		x--;
		c--;
		Q[i] = Query(x, d, c);
	}

	FILL(C, -1);

	RFOR(i, q, 0)
	{
		int x = Q[i].x;
		int d = Q[i].d;
		int c = Q[i].c;

		dfs(x, d, c);
	}

	FOR (i, 0, n)
	{
		printf("%d\n", C[i] + 1);
	}


}


Measured memory_bytes: 9976