akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

  char c;
  cin >> c;
  
  switch(c){
    case 'A':
      COUT('T');
      break;
    case 'T':
      COUT('A');
      break;
    case 'C':
      COUT('G');
      break;
    case 'G':
      COUT('C');
      break;
  }
  
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n= readLine()!!.toInt()
    val a= readLine()!!.split(" ").map { it.toInt() }

    val ans = when(n%2){
        1    -> (0..n-1).map { (it+1)/2*2 }
        else -> (0..n-1).map { 1+(it)/2*2 }
    }
    
    if (a.sorted()!=ans){
        println(0)
    }else{
        println( (1..n/2).fold(1L){ acc, o-> (acc*2)%1000000007L } )
    }

}



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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int B[N-1]; rep(i,N-1) cin >> B[i];
  int A[N]={};
  rep(i,N) {
    if (i==0) { A[i] = B[0]; continue; }
    if (i==N-1) { A[i] = B[N-2]; continue; }
    A[i] = min(B[i], B[i-1]);
  }
  int result = 0; rep(i,N) result += A[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define maxn 100005
using namespace std;

int dp[maxn], ans[maxn];
vector<int> G[maxn];
int n, mod;

void dfs(int x, int p) {
    dp[x] = 1;
    for(int y : G[x]) {
        if(y == p) continue;
        dfs(y, x);
        dp[x] = dp[x] * (dp[y] + 1) % mod;
    }
}

void DFS(int x, int p, int T) {
    ans[x] = dp[x] * (T + 1) % mod;
    vector<int> L(G[x].size());
    vector<int> R(G[x].size());
    for(int i = 0; i < (int)G[x].size(); i++) {
        int v = (G[x][i] == p ? T : dp[G[x][i]]) + 1;
        if(i) L[i] = L[i - 1] * v % mod;
        else {
            L[i] = v;
        }
    }
    for(int i = (int)G[x].size() - 1; i >= 0; i--) {
        int v = (G[x][i] == p ? T : dp[G[x][i]]) + 1;
        if(i != (int)G[x].size() - 1) R[i] = R[i + 1] * v % mod;
        else {
            R[i] = v;
        }
    }
    for(int i = 0; i < (int)G[x].size(); i++) {
        int y = G[x][i];
        if(y == p) continue;
        int ll = i == 0 ? 1 : L[i - 1];
        int rr = i == (int)G[x].size() - 1 ? 1 : R[i + 1];
        DFS(y, x, ll * rr % mod);
    }

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> mod;
    for(int i = 1; i < n; i++) {
        int x, y; cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1, -1); DFS(1, -1, 0);
    for(int i = 1; i <= n; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}

/*
dp[x] *= dp[y]
*/


Measured memory_bytes: 20936
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n-1];
    int b[1000000];
    for (int i=0; i<n-1; i++){
        cin >> a[i];
        b[a[i]-1] += 1;
    }
    for (int i=0; i<n; i++){
        cout << b[i] << endl;
    }
}

Measured memory_bytes: 5160
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

ans=[]
o=list(input())
e=list(input())
for i in range(len(e)):
    ans.append(o[i])
    ans.append(e[i])
if len(o)-len(e):
    ans.append(o[-1])
print(*ans,sep="")

Measured memory_bytes: 38256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;

struct node{
  int key;
  node *next;
  node *prev;
};

node *a;

void insert(int key){
  node *x = (node *)malloc(sizeof(node));
  x->key = key;
  x->next = a->next;
  a->next->prev = x;
  a->next = x;
  x->prev = a;
}

node *Searchlist(int key){
  node *search = a->next;
  while(search != a && search->key != key){
    search = search->next;
  }
  
  return search;
  
}

void init(){
  a = (node *)malloc(sizeof(node));
  a->next = a;
  a->prev = a;
}

void delNode(node *search){
  if(search == a) return;
  search->prev->next = search->next;
  search->next->prev = search->prev;
  free(search);
}

void delKey(int key){
  delNode(Searchlist(key));
}

void delFirst(){
  delNode(a->next);
}

void delLast(){
  delNode(a->prev);
}

void print(){
  node *out = a->next;
  int j = 0;

  while(1){
    if(out == a) break;
    if(j++ > 0) printf(" ");

    printf("%d", out->key);
    out = out->next;
  }

  printf("\n");
  
}

int main(){
  int n;
  scanf("%d", &n);
  
  int key;
  int cnt = 0;
  int p = 0;
  int d = 0;
  char s[50];
  
  init();
  
  for(int i = 0; i < n; i++){
    scanf("%s%d", s, &key);
    
    if(s[0] == 'i'){
      insert(key);
      p++;
      cnt++;
    }
    
    else if(s[0] == 'd'){
      
      if(strlen(s) > 7){
	if(s[6] == 'F') delFirst();

	else if(s[6] == 'L') delLast();
      }
      
      else{
	delKey(key);
	d++;
      }
    
      cnt--;
    }
  }

  print();
  
  return 0;
  
}



Measured memory_bytes: 34404
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define ll long long
#define fi first
#define fs first
#define se second
#define sc second
//#define int long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;
 
int n;
vec dp;
 
void solve() {
    vector<P> a(n);
    int sum1 = 0, sum2 = 0;
    REP(i, n) cin >> a[i].fs >> a[i].sc, sum1 += a[i].fs, sum2 += a[i].sc;
 
    sort(a.begin(), a.end());
 
    if (sum1 >= a.back().fs * 2) {
        cout << sum1 + sum2 << endl;
        return;
    }
 
    int k = a.back().fs * 2 - sum1;
    vec dp(k + 1, 0);
    dp[0] = 1;
 
    REP(i, n - 1) {
        RREP(j, k) {
            if (j + a[i].sc <= k) dp[j + a[i].sc] |= dp[j];
        }
    }
 
    int mx = 0;
    REP(i, k + 1) if (dp[i]) mx = i;
 
    cout << a.back().fs * 2 + sum2 - mx << endl;
}
 
int main() {
    while (cin >> n, n) solve();
}


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

using namespace std;

#define SZ(x) ((int)x.size())

const int N = (int)2e5+5;
const int mod = 998244353;
int n, m, dp[N][3], dp2[N][3][3];
string s;

char change(char x, char y) {
	if ((x == 'a' && y == 'b') || (x == 'b' && y == 'a')) return 'c';
	if ((x == 'c' && y == 'b') || (x == 'b' && y == 'c')) return 'a';
	return 'b';
}

void gen_all() {
	map<string, bool> vis;
	queue<string> q;
	q.push(s);
	vis[s] = true;
	while (SZ(q)) {
		string u = q.front(); q.pop();
		for (int i = 0; i < n - 1; ++i) {
			if (u[i] == u[i + 1]) continue;
			string v = "";
			v.assign(u);
			char now = change(v[i], v[i + 1]);
			v[i] = now, v[i + 1] = now;
			if (vis[v]) continue;
			vis[v] = true;
			q.push(v);
		}
	}
	cout << SZ(vis) << "\n";
}

int main() {
	cin >> s;
	n = SZ(s);
	int add = 1;
	bool all_same = true;
	for (int i = 0; i < n; ++i) {
		m = (m + s[i] - 'a') % 3;
		if (i > 0 && s[i - 1] == s[i]) add = 0;
		if (i > 0 && s[i] != s[i - 1]) all_same = false;
	}
	if (all_same) return puts("1"), 0;
	if (n < 4) {
		gen_all();
		return 0;
	}
	dp[0][0] = 1, dp2[1][0][0] = dp2[1][1][1] = dp2[1][2][2] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				dp[i][j] = (dp[i][j] + dp[i - 1][(j - k + 3) % 3]) % mod;
				if (i == 1) continue;
				for (int l = 0; l < 3; ++l) {
					if (l == k) continue;
					dp2[i][j][k] = (dp2[i][j][k] + dp2[i - 1][(j - k + 3) % 3][l]) % mod;
				}
			}
		}
	}
	int ans = dp[n][m];
	for (int i = 0; i < 3; ++i) {
		ans = (ans - dp2[n][m][i] + mod) % mod;
	}
	cout << (ans + add) % mod << "\n";
	return 0;
}

Measured memory_bytes: 9988
module StringSet = Set.Make (String)

let () =
  let n = int_of_string @@ read_line () in
  let ws = Array.init n @@ fun _ -> read_line () in
  let wss = Array.make (n + 1) StringSet.empty in
  for i = 0 to n - 1 do
    wss.(i + 1) <- StringSet.add ws.(i) wss.(i)
  done;
  print_endline @@
  if
    Array.fold_left ( && ) true @@
    Array.init (n - 1) @@ fun i ->
      not (StringSet.mem ws.(i + 1) wss.(i + 1)) && ws.(i).[String.length ws.(i) - 1] = ws.(i + 1).[0]
  then "Yes"
  else "No"


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

int main(){
    int N;
    for(scanf("%d", &N); N--;){
        char pz[9][12] = {};
        char res[9][12] = {};
        for(int i = 0; i < 9; i++){
            for(int j = 0; j < 9; j++){
                scanf(" %c", &pz[i][j]);
            }
        }
        for(int i = 0; i < 9; i++){
            for(int j = 0; j < 9; j++){
                bool flg = true;
                for(int k = 0; k < 9; k++){
                    if(i == k) continue;
                    if(pz[i][j] == pz[k][j]) flg = 0;
                }
                for(int k = 0; k < 9; k++){
                    if(j == k) continue;
                    if(pz[i][j] == pz[i][k]) flg = 0;
                }
                int r = i/3*3, c = j/3*3;
                for(int k = 0; k < 3; k++){
                    for(int l = 0; l < 3; l++){
                        if(r + k == i && c + l == j) continue;
                        if(pz[i][j] == pz[r+k][c+l]) flg = 0;
                    }
                }
                if(flg){
                    res[i][j] = ' ';
                }else{
                    res[i][j] = '*';
                }
            }
        }
        for(int i = 0; i < 9; i++){
            for(int j = 0; j < 9; j++){
                printf("%c", res[i][j]);
                printf("%c", pz[i][j]);
            }
            puts("");
        }
        if(N>=1) puts("");
    }
    return 0;
}

Measured memory_bytes: 1012
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<bits/stdc++.h>
using namespace std;
int read()
{
	int kk(0);
	bool fh=true;
	char ch=getchar();
	for(;ch<'0'||ch>'9';)
	{
		if(ch=='-')fh=false;
		ch=getchar();
	}
	for(;ch>='0'&&ch<='9';)
	{
		kk=(kk<<3)+(kk<<1)+(ch^48);
		ch=getchar();
	}
	return fh?kk:-kk;
}
long long readll()
{
	long long kk(0);
	bool fh=true;
	char ch=getchar();
	for(;ch<'0'||ch>'9';)
	{
		if(ch=='-')fh=false;
		ch=getchar();
	}
	for(;ch>='0'&&ch<='9';)
	{
		kk=(kk<<3)+(kk<<1)+(ch^48);
		ch=getchar();
	}
	return fh?kk:-kk;
}
#define INF 214748364
#define MOD 1000000007
#define MAXN
char s[100010],s1[100010];
map<char,char> mp;
int main()
{
	mp['d']='b';
	mp['b']='d';
	mp['q']='p';
	mp['p']='q';
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++)s1[len-i-1]=s[i];
	for(int i=0;i<len;i++)s1[i]=mp[s1[i]];
	if(strcmp(s,s1)==0)puts("Yes");
	else puts("No");
	return 0;
}

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

int main(){

    int c[3][3];

    
    int C;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> C;
            c[i][j] = C;
        }
    }
    int a[3], b[3];
    a[0] = 0;
    b[0]= c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    bool flag = true;

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(a[i]+ b[j] != c[i][j]){
                flag = false;
                break;
            }
        }
    }

    if(flag == true){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}



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

struct edge {
    int to;
    int cost;
    int numOfTheaf;
};

struct info {
    int now;
    int sumOfCost;
    int sumOfTheaf;
    bool operator < (const info &o) const {
        return  sumOfTheaf > o.sumOfTheaf;
    }
};

int main() {
    int n, m, l;
    while (cin >> n >> m >> l, n) {
        vector <vector <edge> > G(n);
        rep (i, m) {
            int a, b, d, e;
            cin >> a >> b >> d >> e;
            a--; b--;
            G[a].push_back({b, d, e});
            G[b].push_back({a, d, e});
        }
        //       to, sumOfCost -> sumOfTheaf
        int dist[110][110] = {}; rep (i, 110) rep (j, 110) dist[i][j] = 1e9;
        bool used[110][110] = {};

        //info -> now, sumOfCost, sumOfTheaf
        priority_queue <info> que;
        que.push({0, 0, 0});

        dist[0][0] = 0;

        while (!que.empty()) {
            info tmp = que.top(); que.pop();
            rep (i, G[tmp.now].size()) {
                //護衛を雇わない場合
                {
                    if ( dist[G[tmp.now][i].to][tmp.sumOfCost] > dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf ) {
                        dist[G[tmp.now][i].to][tmp.sumOfCost] = dist[tmp.now][tmp.sumOfCost] + G[tmp.now][i].numOfTheaf;
                        que.push({G[tmp.now][i].to, tmp.sumOfCost, dist[G[tmp.now][i].to][tmp.sumOfCost]});
                    }
                }
                //護衛を雇う場合
                {
                //お金こえちゃだめ
                    if ( G[tmp.now][i].cost + tmp.sumOfCost > l ) continue;
                    if ( dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] > dist[tmp.now][tmp.sumOfCost] ) {
                        dist[G[tmp.now][i].to][tmp.sumOfCost + G[tmp.now][i].cost] = dist[tmp.now][tmp.sumOfCost];
                        que.push({G[tmp.now][i].to, tmp.sumOfCost + G[tmp.now][i].cost, tmp.sumOfTheaf});
                    }
                }
            }
        }
        int ans = 1e9;
        rep (i, l + 1) ans = min(ans, dist[n - 1][i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  string s;
  cin>>s;
  bool ex=true;
  if(s[0]!='A') ex=false;
  int c=0,cnt=0;
  int n=s.size();
  for(int i=2;i<n-1;i++){
    if(s[i]=='C')
      c++;
  }if(c!=1) ex=false;
  rep(i,n){
    if(isupper(s[i]))
      cnt++;
  }if(cnt!=2) ex=false;
  
  if(ex) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}

Measured memory_bytes: 3604
import itertools
while True:
    count = 0
    n, x = map(int, raw_input().split())
    if n==0 and x==0:
        break
    #for i in xrange(1, n):
     #   for j in xrange(1, n):
      #      for k in xrange(1, n):
       #         if i!=j and  j!=k and k!=i and i+j+k==x:
    #print count
    ls = list(itertools.combinations(xrange(1, n+1), 3))
    #print ls
    l = len(ls)
    for i in xrange(l):
        if ls[i][0]+ls[i][1]+ls[i][2]==x:
            count+=1
    print count

#for x in itertools.combinations_with_replacement()

Measured memory_bytes: 34816
n = int(input())
A = list(map(int, input().split()))
A.sort()

total = 0
count = 1
for i in range(1, n):
  if 2 * (A[i - 1] + total) >= A[i]:
    count += 1
  else:
    count = 1
  total += A[i - 1]
print(count)

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

int main(){
    int time[5];
    cin >> time[0] >> time[1] >> time[2] >> time[3] >> time[4];
    int min_hitoketa=9; int min_index=0;
    int shou[5];
    for(int index=0; index<5; index++){
        if((time[index] % 10 < min_hitoketa ) && (time[index] % 10 != 0)){
            min_hitoketa = time[index] % 10;
            min_index = index;
            shou[index] = time[index] / 10;
            shou[index] += 1;
        }
        else if(time[index] % 10 == 0){
            shou[index] = time[index] / 10;
        }
        else{
            shou[index] = time[index] / 10;
            shou[index] += 1;
        }
    }
    int res = 0;
    for (int index=0; index<5; index++){
        if(index != min_index){
            res += shou[index] * 10;
        }
        else{
            res += (shou[index]-1) * 10 + min_hitoketa;
        }
    }
    int flag = 0;
    int sum = 0;
    for(int index=0; index<5; index++){
        if(time[index] % 10 != 0) flag = 1;
        sum += time[index];
    }
    if(flag == 1) cout << res << endl;
    else cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
int a,b,num;
scanf("%d %d",&a,&b);
if(b>a)
{
num=a;
while(b>1)
{
num=num*10;
num+=a;
b--;
}
}
else
{
num=b;
while(a>1)
{
num=num*10;
num+=b;
a--;
}
}
printf("%d\n",num);
}


Measured memory_bytes: 128
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		// 入力
		final int n, k ,x, y;
		try(Scanner scan = new Scanner(System.in)) {
			n = scan.nextInt();	// 1≤N,K≤10000
			k = scan.nextInt();
			x = scan.nextInt();	//1≤Y<X≤10000
			y = scan.nextInt();
		}
		
		int result = n <= k ? n * x : n * x + (n - k) * (y - x);
		
		// 出力
		try (PrintWriter out = new PrintWriter(System.out)) {
			out.println(result);
		}

	}

}


Measured memory_bytes: 10068
#include <stdio.h>

void Judge(int M, int F, int R);

int main(void) {
  int m, f, r;

  while(1) {
    scanf("%d %d %d", &m, &f, &r);

    if(m == -1 && f == -1 && r == -1) break;

    if(m == -1 || f == -1) {
      puts("F");
      continue;
    }

    Judge(m, f, r);
  }

  return 0;
}

void Judge(int M, int F, int R) {
  int Score = M+F;

  if(Score >= 80) {
    puts("A");
  }
  else if(Score >= 65) {
    puts("B");
  }
  else if(Score >= 50) {
    puts("C");
  }
  else if(Score >= 30) {
    if(R >= 50) puts("C");
    else puts("D");
  }
  else puts("F");
  
}



Measured memory_bytes: 2044
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


m = Mod(10**9 + 7)


@mt
def slv(N, M, A):
    dp = [0] * (N+3)
    b = [False] * (N+3)
    for a in A:
        b[a] = True

    A.sort(reverse=True)
    dp[0] = 1
    for i in range(N):
        if not b[i+1]:
            dp[i+1] = m.add(dp[i+1], dp[i])
        if not b[i+2]:
            dp[i+2] = m.add(dp[i+2], dp[i])
    return dp[N]


def main():
    N, M = read_int_n()
    A = [read_int() for _ in range(M)]
    print(slv(N, M, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11204
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
#include<utility>
#define inf 0x3f3f3f3f
#define lowbit(x) (x&-x)
typedef long long ll;

const int maxn=1e5+5;
const int mod=1e9+7;

using namespace std;
typedef pair<int,int>P;
int n,a[maxn],b[maxn];
int main()
{
    scanf("%d",&n);
    int flag=0;
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i],&b[i]);
    for(int i=3;i<=n;i++)
    {
        if(a[i]==b[i]&&a[i-1]==b[i-1]&&a[i-2]==b[i-2])
        {
            flag=1;
            break;
        }
    }
    if(flag)
        printf("Yes\n");
    else
        printf("No\n");
}


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



int main(){
    map < long long, bool > q;
    long long s;
    cin >> s;
    for(int i = 1; ; i++){
        if(q.find(s) != q.end()){
            return cout << i, 0;
        }
        q[s] = true;
        if(s % 2 == 0){
            s /= 2;
        }
        else{
            s *= 3;
            s += 1;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int solve(int *, int, int, int);

int main(){
  int i, j, n, q, A[20], m[200], ans;
  scanf("%d", &n);
  if(n > 0 && n <= 20){
    for(i = 0; i < n; i++){
      scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    if(q > 0 && q <= 200){
      for(i = 0; i < q; i++){
	scanf("%d", &m[i]);
      }

      for(i = 0; i < q; i++){
	ans = solve(&A[0], m[i], n, 0);
	if(ans == 1){
	  printf("yes\n");
	}else{
	  printf("no\n");
	}
      }
      
    }
  }
  return 0;
}

int solve(int *A, int m,  int n, int i){
  int res;
  if(m == 0){
    return 1;
  }
  if(i >= n){
    return 0;
  }

  res = solve(&A[0], m, n, i + 1) || solve(&A[0], m - A[i], n, i + 1);
  return res;  
}






Measured memory_bytes: 2052
N = int(input()) # 数字を変数に格納
List = list(map(int,input().split())) # 複数の数字をリストに格納

error_list = []

for i in range(N):
    if List[i] != i+1:
        error_list.append(i)
        
if len(error_list) == 0:
    print('YES')
elif len(error_list) == 2:
    first = error_list[0]
    second = error_list[1]
    if List[first] == (second+1) and List[second] == (first+1):
        print('YES')
    else:
        print('NO')
else:
    print('NO')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <numeric>
 
using namespace std;
int main(void) {
    string n;
    cin >> n;
    if(n.length() == 2){
        cout << n << endl;
    }else{
        string s;
        for(int i = 2; i >= 0; i--){
            s = s + n[i];
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

point = 0
flg=[0]*n
for i in range(n):
  if t[i] == 'r' and flg[i] == 0:
    point += p
  elif t[i] == 's' and flg[i] == 0:
    point += r
  elif t[i] == 'p' and flg[i] == 0:
    point += s

  if i+k < n and t[i+k] == t[i]:
    if t[i] == 'r' and flg[i] == 0:
      flg[i+k] = 'r'
    elif t[i] == 's' and flg[i] == 0:
      flg[i+k] = 's'
    elif t[i] =='p' and flg[i] == 0:
      flg[i+k] = 'p'
print(point)

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

string s;
long long n;
vector<long long> memo;

long long solve();

int main() {
  cin >> s;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  n = s.size();
  memo.assign(n + 1, 0);
  long long ans = 0;
  for(int i = 0; i < n;) {
    char now = s[i];
    int l = i;
    while(s[i] == now) ++i;
    if(now == '<') {
      for(int j = l + 1; j <= i; ++j)
        memo[j] = max(memo[j], memo[j - 1] + 1);
    }
    else {
      for(int j = i - 1; j >= l; --j)
        memo[j] = max(memo[j + 1] + 1, memo[j]);
    }
  }
  for(int i = 0; i < n + 1; ++i) ans += memo[i];
  return ans;
}

Measured memory_bytes: 4740
#include <iostream>

using namespace std;

typedef long long ll;

int N,K;
int h[100000];

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> h[i];
    int count = 0;
    for(int i=0;i<N;i++){
        if(h[i] >= K) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int H = scn.nextInt();
		int W = scn.nextInt();
		H -= scn.nextInt();
		W -= scn.nextInt();
		System.out.println(H*W);
		scn.close();
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,a[20],b[20],e,o,res,cnd;
vector<pair<int,int> > even,odd,vc;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	o=n/2;
	e=n-o;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	res=1e9;
	for(int msk=0;msk<(1<<n);msk++){
		even.clear();odd.clear();vc.clear();
		for(int i=0;i<n;i++){
			if(msk&(1<<i)){
				if(i%2==0) odd.push_back(make_pair(b[i],i));
				else even.push_back(make_pair(b[i],i));
			}
			else{
				if(i%2==0) even.push_back(make_pair(a[i],i));
				else odd.push_back(make_pair(a[i],i));
			}
		}
		sort(even.begin(),even.end());
		sort(odd.begin(),odd.end());
		if((even.size()!=e)||(odd.size()!=o)) continue;
		for(int i=0;i<o;i++){
			vc.push_back(even[i]);
			vc.push_back(odd[i]);
		}
		if(e!=o) vc.push_back(even[e-1]);
		cnd=0;
		for(int i=1;i<n;i++){
			if(vc[i].first<vc[i-1].first){
				cnd=-1;
				break;
			}
		}
		if(cnd==-1)
			continue;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				cnd+=((vc[j].second)<(vc[i].second));
			}
		}
		res=min(res,cnd);
	}
	if(res==1e9) res=-1;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (n * a > b)
            System.out.println(b);
        else
            System.out.println(n * a);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> p(N+1);
    ll sub = 0;
    for (ll i = 1; i <= N; i++) {
        cin >> p[i];
        if (p[i] != i) {
            sub++;
        }
    }

    if (sub <= 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

Measured memory_bytes: 256
// Frog 1.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
using namespace std;
const int G = 1000 * 100 + 10;
int a[G];
long long dp[G];

int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	long long m;
	dp[1] = abs(a[0] - a[1]);
	for (int i = 2; i < n; i++){
		m = 1000000000000;
		for (int  j = max(0,i-k); j < i; j++){
			m = min(m , dp[j] + abs(a[i] - a[j]));
		}
		dp[i] = m;
	}
	cout << dp[n-1] << endl;
	return 0;
}



Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T buf; cin >> buf; return buf; }

char str_in[1 << 16];
long input_pre() {
  char* head = str_in;
  while (fgets(head, 1 << 16, stdin)) {
    while (*head) {
      ++head;
    }
  }
}

long input() {
  static const char* head = str_in;
  while (!isdigit(*head)) ++head;
  
  long ret = 0;
  char c;
  while (isdigit(*head)) {
    ret *= 10;
    ret += *head - '0';
    ++head;
  }
  return ret;
}

static char str_out[1 << 16];
void output(long val) {
  static char* head = str_out;
  static char buf[20];
  
  char* buf_head = buf;
  while (val > 0) {
    *buf_head = '0' + val % 10;
    ++buf_head;
    val /= 10;
  }
  
  for (char* p = buf_head - 1; p >= buf; --p) {
    *head = *p;
    ++head;
  }
  
  *head = '\n';
  ++head;
}

void post() {
  puts(str_out);
}

const long INFLL = 1e18;
long s[1001];
long t[1001];
long u[1001];
long ds[1000];
long dt[1000];
long du[1000];
int main() {
  input_pre();
  int a = input();
  int b = input();
  int c = input();
  int z = input();
  
  for (int i = 0; i < a; ++i) s[i] = input();
  for (int i = 0; i < b; ++i) t[i] = input();
  for (int i = 0; i < c; ++i) u[i] = input();
  sort(s, s + a, greater<long>());
  sort(t, t + b, greater<long>());
  sort(u, u + c, greater<long>());
  s[a] = -INFLL;
  t[b] = -INFLL;
  u[c] = -INFLL;
  
  for (int i = 0; i < a; ++i) ds[i] = s[i] - s[i + 1];
  for (int i = 0; i < b; ++i) dt[i] = t[i] - t[i + 1];
  for (int i = 0; i < c; ++i) du[i] = u[i] - u[i + 1];
  
  using Pair = pair<long, int>;
  
  unordered_map<int, int> mp;
  mp.reserve(3 * z + 1);
  
  int ppp = clock();
  vector<Pair> mem;
  mem.reserve(2 * z + 1);
  priority_queue<Pair> Q(less<Pair>(), move(mem));
  Q.push(make_pair(s[0] + t[0] + u[0], 0));
  
  int cnt = 0;
  while (cnt < z) {
    auto q = Q.top(); Q.pop();
    long sc = q.first;
    int pos = q.second;
    
    int i =  pos        & 0x3ff;
    int j = (pos >> 10) & 0x3ff;
    int k = (pos >> 20) & 0x3ff;
    
    output(sc);
    
    int nposi = pos + 1;
    int nposj = pos + (1 << 10);
    int nposk = pos + (1 << 20);
    int ci = ++mp[nposi];
    int cj = ++mp[nposj];
    int ck = ++mp[nposk];
    
    int needi = !!(nposi & 0x3ff) + !!((nposi >> 10) & 0x3ff) + !!((nposi >> 20) & 0x3ff);
    int needj = !!(nposj & 0x3ff) + !!((nposj >> 10) & 0x3ff) + !!((nposj >> 20) & 0x3ff);
    int needk = !!(nposk & 0x3ff) + !!((nposk >> 10) & 0x3ff) + !!((nposk >> 20) & 0x3ff);
    if (ci == needi) Q.push(make_pair(sc - ds[i], nposi));
    if (cj == needj) Q.push(make_pair(sc - dt[j], nposj));
    if (ck == needk) Q.push(make_pair(sc - du[k], nposk));
    ++cnt;
  }
  
  post();
  int qqq = clock();

  cerr << (double)(qqq - ppp) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 640
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    L = read_ints()
    L.sort()
    answer = 0
    for i in range(2, N):
        for j in range(1, i):
            start, end = -1, j
            while end-start > 1:
                mid = start+(end-start)//2
                if L[i]-L[j] < L[mid]: # valid
                    end = mid
                else:
                    start = mid
            answer += j-end
    return answer


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 80204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.math.*;
import java.util.*;
class Main{

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] s1 = br.readLine().split(" ");
        
        int D = Integer.parseInt(s1[0]);
        int T = Integer.parseInt(s1[1]);
        int S = Integer.parseInt(s1[2]);

        if(T * S >= D){
            System.out.print("Yes");
        }else{
            System.out.print("No");
        }

    }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,l,r;
	cin >> n;
	ll ans=0;
	rep(i,n){
		cin >> l >> r;
		ans+=r-l+1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b,c,x;
 /* ????????°a ?????¢?????¬?????????????????¢?????¨?????¢?????\?????????????????´??°????????????????´???????????????????????????????*/
      scanf("%d%d%d", &a,&b,&c);
  if (b < a)
    {
   x = a;
      a = b;
      b = x;
    };

   if (c < b)
    {
   x = b;
      b = c;
      c = x;
    };

   if (b < a)
    {
   x = a;
      a = b;
      b = x;
    };
      printf("%d ", a);
  printf("%d ", b);
  printf("%d\n", c);
  
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();

		String ans = (t.substring(0, t.length() - 1).equals(s)) ? "Yes" : "No";
		System.out.println(ans);
	}

}


Measured memory_bytes: 35564
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a, b, cnt = 0;
	cin >> a >> b;
	for(long long i=b + 1; i<=a; i++)
	{
		long long temp = i;
		cnt += (a / temp) * max(0ll, temp - b);
		temp = a % temp;
		cnt += max(0ll, temp - b + 1);
	}
	if(b == 0) cnt -= a;
	cout << cnt << '\n';
	return 0;
}

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

using namespace std;
typedef complex<long double> point;
#define X real()
#define Y imag()
#define vec(a, b) ((b)-(a))
#define mid(a, b) (((a)+(b))/point(2,0))
#define dot(a, b) ((conj(a)*(b)).real())
#define cross(a, b) ((conj(a)*(b)).imag())
#define EPS 1e-9
#define length(v) ((long double)hypot((v).Y,(v).X))
#define perp(a) (point(-(a).Y,(a).X))
#define lengthSqr(v) (dot(v,v))
enum STATE {
	IN, OUT, BOUNDRY
};
const int N = 22;
point p[N], r[3], cen;
int ps, rs;
long double rad;

bool intersect(const point &a, const point &b, const point &p, const point &q,
			   point &ret) {
	//handle degenerate cases (2 parallel lines, 2 identical lines,   line is 1 point)
	long double d1 = cross(p - a, b - a);
	long double d2 = cross(q - a, b - a);
	ret = (d1 * q - d2 * p) / (d1 - d2);
	if (fabs(d1 - d2) > EPS) return 1;
	return 0;
}
void circle2(const point &p1, const point &p2, point &cen, long double &r) {
	cen = mid(p1, p2);
	r = length(vec(p1, p2)) / 2;
}

bool circle3(const point &p1, const point &p2, const point &p3, point &cen,
			 long double &r) {
	point m1 = mid(p1, p2);
	point m2 = mid(p2, p3);
	point perp1 = perp(vec(p1, p2));
	point perp2 = perp(vec(p2, p3));
	bool res = intersect(m1, m1 + perp1, m2, m2 + perp2, cen);
	r = length(vec(cen, p1));
	return res;
}
STATE circlePoint(const point &cen, const long double &r, const point &p) {
	long double lensqr = lengthSqr(vec(cen, p));
	if (fabs(lensqr - r * r) < EPS)
		return BOUNDRY;
	if (lensqr < r * r)
		return IN;
	return OUT;
}

void mec() {
	if (rs == 3) {
		circle3(r[0], r[1], r[2], cen, rad);
		return;
	}
	if (rs == 2 && ps == 0) {
		circle2(r[0], r[1], cen, rad);
		return;
	}
	if (!ps) {
		cen = r[0];
		rad = 0;
		return;
	}
	ps--;
	mec();
	if (circlePoint(cen, rad, p[ps]) == OUT) {
		r[rs++] = p[ps];
		mec();
		rs--;
	}
	ps++;
	
}
int main() {
//	freopen("input.in", "r", stdin);
	scanf("%d", &ps);
	for (int i = 0; i < ps; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		p[i] = {x, y};
	}
	random_shuffle(p, p + ps);
	mec();
	printf("%.9Lf\n", rad);
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int i, j, len;
    char s[201];

    scanf("%s",s);

    len = strlen(s);
    for (i = 2; i < len; i += 2){
        for (j = 0; j < (len - i) / 2; j++){
            if(s[j] != s[j + (len - i) / 2])break;
            }
            if(j == (len - i) / 2)break;
    }
            printf("%d",j * 2);
    

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		n=sc.nextInt();
		a=new int [n];
		boolean pos=false;
		boolean neg=false;
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
			if(a[i]<0)
				neg=true;
			if(a[i]>0)
				pos=true;
		}
		if(!neg){
			pw.println(n-1);
			for(int i=1;i<n;i++)
				pw.println(i+" "+(i+1));
		}else
			if(!pos){
				pw.println(n-1);
				for(int i=n;i>1;i--)
					pw.println(i+" "+(i-1));
			}else{
				int idxmax=0;
				int max=0;
				for(int i=0;i<n;i++)
					if(Math.abs(a[i])>max){
						max=Math.abs(a[i]);
						idxmax=i;
					}
				ArrayList<Integer> x=new ArrayList<Integer>();
				ArrayList<Integer> y=new ArrayList<Integer>();
				for(int i=0;i<n;i++){
					if(a[idxmax]<0 && a[i]>0){
						x.add(idxmax+1);
						y.add(i+1);
					}
					if(a[idxmax]>0 && a[i]<0){
						x.add(idxmax+1);
						y.add(i+1);
					}
				}
				pw.println(n-1+x.size());
				for(int i=0;i<x.size();i++)
					pw.println(x.get(i)+" "+y.get(i));
				if(a[idxmax]<0){
					for(int i=n;i>1;i--)
						pw.println(i+" "+(i-1));
				}else{
					for(int i=1;i<n;i++)
						pw.println(i+" "+(i+1));
				}
			}
		
		pw.flush();
		pw.close();
	}
	static int n;
	static int [] a;
	
	static class MyScanner{
		BufferedReader br;
		StringTokenizer st;
		
		MyScanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		String next(){
			while(st==null || !st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
	}
}


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


int main() {
    string n;
    cin >> n;
    int tmp = 1;
    bool flag = false;
    for (int i = 1; i < 4; i++){
        if (n.at(i) == n.at(i - 1)) tmp++;
        else tmp = 1;
        if (tmp == 3) flag = true;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD>
struct Fp {
    long long val;

    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }

    constexpr int getmod() { return MOD; }

    constexpr Fp operator-() const noexcept {
        return val ? MOD - val : 0;
    }

    constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }

    constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }

    constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }

    constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }

    constexpr Fp &operator+=(const Fp &r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }

    constexpr Fp &operator-=(const Fp &r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }

    constexpr Fp &operator*=(const Fp &r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }

    constexpr Fp &operator/=(const Fp &r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }

    constexpr bool operator==(const Fp &r) const noexcept {
        return this->val == r.val;
    }

    constexpr bool operator!=(const Fp &r) const noexcept {
        return this->val != r.val;
    }

    friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
        return os << x.val;
    }

    friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
        return is >> x.val;
    }

    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;


int N, M;
vector<int> S, T;
mint dp[2100][2100]; // dp[i][j] => S[i-1] == T[j-1]のとき dp[i][j] = sdp[i][j], S[i-1] != T[j-1]のとき dp[i][j] = 0
mint sdp[2100][2100]; // 2次元累積和

int main() {
    cin >> N >> M;
    S.resize(N), T.resize(M);
    for (int i = 0; i < N; ++i) cin >> S[i];
    for (int i = 0; i < M; ++i) cin >> T[i];

    memset(dp, 0, sizeof(dp));
    memset(sdp, 0, sizeof(dp));
    dp[0][0] = 1;
    sdp[1][1] = 1;
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= M; ++j) {
            if (i == 0 && j == 0) continue;
            if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
                dp[i][j] = sdp[i][j];
            }
            sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j];
        }
    }
    cout << sdp[N + 1][M + 1] << endl;
}

Measured memory_bytes: 69120
#include <bits/stdc++.h>
#define int long long
#define multi_test true and false
#define all(a) (a).begin(), (a).end()
using namespace std;

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for (int &i : arr)
        cin >> i;
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if (j + i < n)
            {
                dp[j + i] = min(dp[j + i], dp[i] + abs(arr[j + i] - arr[i]));
            }
        }
    }
    cout << dp.back() << endl;
}

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

    int test = 1;
    if (multi_test)
        cin >> test;
    while (test--)
        solve();

    return 0;
}

Measured memory_bytes: 1792
import math
A, B, H, M = map(int, input().split())
Longdegree = H * 30 + M * 0.5
Shortdegree =  M * 6
LSdegree = abs(Longdegree - Shortdegree)
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(LSdegree))))


Measured memory_bytes: 9436
import sys
from math import floor

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


A, B, N = map(int, read().split())

x = min(B-1, N)

ans = floor((A * x) / B) - A * floor(x/B)

print(ans)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long A, long long B){
  if (A==0) return B;
  if (B==0) return A;
  return gcd(max(A,B)-min(A,B),min(A,B));
}
int main(){
  long long A,B;
  cin >> A >> B;
  cout << A*B/gcd(A,B);
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] B = new int[N];

        for (int i = 1; i <= N - 1; i++) {
            B[i] = sc.nextInt();
        }

        int sum = B[N - 1]; // decide A[N]
        for (int i = N - 1; i >= 1; i--) {
            // decide A[i]
            sum += Math.min(B[i], B[i - 1]);
        }
        sum += B[1];

        System.out.println(sum);
        return;
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define LL long long 
using namespace std;
inline int read(){
    int x = 0; char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0',c = getchar();
    return x;
}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
int n;
int cnt[10][10];
inline int Mx(int x){
	while (x>=10) x /= 10;
	return x;
} 
inline int Mn(int x){
	while(x%10==0) x/=10;
	return x%10;
}
int main(){
	int i,j; LL ans=0;
	n = read();
	for (i = 1; i <= n; ++i) ++cnt[i%10][Mx(i)];
	for (i = 0; i <= 9; ++i) for (j = 0; j <= 9; ++j) ans += 1ll*cnt[i][j] * cnt[j][i];
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n){
        ll x; cin >> x;
        a[i] = i+1 - x;
    }
    sort(all(a));
    ll b = a[n/2];
    ll res = 0;
    rep(i, n){
        res += abs(a[i] - b);
    }
    cout << res;
    cout << endl;
    return 0;
}



Measured memory_bytes: 1792