akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb insert
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, k;
set<P> v;

int32_t main(){_

   cin>>n>>k;

   int ma = (n-2) * (n-1) / 2;
      
   if (k == 0){

      set<P> v;
      for (int i = 1; i <= n; ++i)
      {
         for (int j = 1; j < i; ++j)
         {
            v.pb({i, j});
         }
      }

      cout<<sz(v)<<endl;

      for(auto it: v)
         cout<<it.F<<' '<<it.S<<endl;

      exit(0);
   }

   if (k > ma){
      cout<<-1;
      exit(0);
   }

   int vals = 0;
   for (int adj = 1; adj <= n; ++adj)
   {
      int tot = adj - 1;
      tot = tot * (tot+1);
      tot >>= 1;
      if(tot <= k){
         vals = adj;
      }
      else{
         break;
      }
   }

   int adj = vals;

   for (int i = 1; i <= adj; ++i)
   {
      v.pb({1, i+1});
   }

   k -= ((adj * (adj - 1)) / 2);

   adj+=2;
   int lst = adj;
   tr(adj, k, v);
   for (int i = adj; i <= n; ++i)
   {
      int poss = adj-2;
      if(k > 0 and k - poss < 0){
         v.pb({i, 1});
         int rem = k;
         k = 0;
         for (int j = 2; j <= adj-rem-1; ++j)
         {
            v.pb({i, j});            
         }
         lst = adj+1;
         break;
      }
   }

   tr(lst, k);

   for (int i = lst; i <= n; ++i)
   {
      for (int j = 1; j <= i-1; ++j)
      {
         v.pb({i, j});
      }
   }

   if(k > 0){
      assert(0);
   }

   cout<<sz(v)<<endl;
   for(auto it: v)
      cout<<it.F<<' '<<it.S<<endl;


   return 0;
}

Measured memory_bytes: 640
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
ans = m
count = 0
for i in range(x+1, n):
    if i in a:
        count += 1
ans = min(ans, count)
count = 0
for i in range(x-1, 0, -1):
    if i in a:
        count += 1
ans = min(ans, count)
print(ans)


Measured memory_bytes: 3060
import math
A,B,H,M=map(int,input().split())
h=H*30+0.5*M
m=6*M
degree=abs(h-m)
degree=min(degree,360-degree)
print((A*A+B*B-2*A*B*math.cos(math.radians(degree)))**(1/2))

Measured memory_bytes: 9512
def change(z,x,y):
    tmp = z[x-1]
    z[x-1] = z[y-1]
    z[y-1] = tmp
    return z


a = int(raw_input())
b = int(raw_input())

c = range(a)
while b > 0:
    in1,in2 = map(int,raw_input().split(','))
    c = change(c,in1,in2)
    b -= 1


for p in c:
    print p+1

Measured memory_bytes: 4236
import java.util.Scanner;
import java.lang.Math;
import java.util.Random;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
//		Random rnd = new Random();
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			int[] ten = new int[n];
			int sum=0;
			for(int i=0; i<n; i++){
				ten[i] = sc.nextInt();
				sum += ten[i];

			}
			int max=0, min=1000;
			for(int i=0; i<n; i++){
				if(ten[i]<min){
					min = ten[i];
				}
				if(ten[i]>max){
					max = ten[i];
				}
			}			

			sum -= min + max;
			
			System.out.println(sum/(n-2));

		}
	}
}

Measured memory_bytes: 29232
#include <iostream>
using namespace std;
int main(void){
    int N, D, X, A[100];
    cin >> N >> D >> X;
    int ans = X;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        ans += (D - 1) / A[i] + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ');
  const A = Number(s[0]);
  const B = Number(s[1]);
  const plus = A + B;
  const minus = A - B;
  const multi = A * B;
  let max = Math.max(...[plus, minus, multi]);
  if (max === +0 || max === -0) max = 0;
  console.log(max);

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

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

    int a_i=200001, z_i= -1;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A') {
            if (a_i > i)
                a_i = i;
        }
        if (s[i] == 'Z') {
            if (z_i < i)
                z_i = i;
        }
    }
    cout << z_i - a_i + 1 << endl;
}

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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<int> v(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	vector<int> odd(100000, 0);
	vector<int> even(100000, 0);
	int maxx = 0;

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			odd[v[i]]++; //数字の個数をカウント配列に入れる
			if (v[i] > maxx) { maxx = v[i]; } //最大の数字を探す
		}
		if (i % 2 != 0) {
			even[v[i]]++; //数字の個数をカウント配列に入れる
			if (v[i] > maxx) { maxx = v[i]; }
		}
	}

	int oddmax = 0;
	int oddnum1 = 0;
	int oddmax2 = 0;
	int oddnum2 = 0;

	int evenmax = 0;
	int evennum1 = 0;
	int evenmax2 = 0;
	int evennum2 = 0;

	for (int i = 0; i < maxx+1; i++) {
		if (odd[i] >= oddmax) { //最大カウントだったら
			oddmax2 = oddmax; //今までの1番を2番目にする
			oddnum2 = oddnum1; //1番の数字を2番の数字にする。
			oddmax = odd[i]; //1は最大カウント数
			oddnum1 = i; //1番の数字を覚えておく
		}
		if (odd[i]<oddmax && odd[i]>oddmax2) {
			oddmax2 = odd[i]; //2番の場合2番だけを処理する。
			oddnum2 = i;
		}
		if (even[i] >= evenmax) {
			evenmax2 = evenmax;
			evennum2 = evennum1;
			evenmax =	even[i];
			evennum1 = i;
		}
		if (even[i]<evenmax && even[i]>evenmax2) {
			evenmax2 = even[i];
			evennum2 = i;
		}
	}

	if (oddnum1 != evennum1) {
		cout << n / 2 - oddmax + n / 2 - evenmax << endl;

	}
	else {
		if (oddmax2 > evenmax2){
			cout << n / 2 - oddmax2 + n / 2 - evenmax << endl;
		}
		else {
			cout << n / 2 - oddmax + n / 2 - evenmax2 << endl;
		}
	}

}

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

using namespace std;

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int i = 0; i * R <= N; i++) {
        const int cur_r = i * R;
        for (int j = 0; cur_r + j * G <= N; j++) {
            const int cur_g = j * G;
            const int cur_b = N - cur_r - cur_g;
            if (cur_b < 0 || (cur_b > 0 && cur_b % B != 0)) {
                continue;
            }
            // cout << cur_r << " " << cur_g << " " << cur_b << endl;
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		for(int i=0;i<27;i++){
			string t=s;
			for(int j=0;j<(int)s.size();j++){
				if('a'<=t[j]&&t[j]<='z')	t[j]='a'+(t[j]-'a'+i)%26;
			}
			if(t.find("the",0)!=string::npos){
				cout<<t<<endl;
				break;
			}
			else if(t.find("that",0)!=string::npos){
				cout<<t<<endl;
				break;
			}
			else if(t.find("this",0)!=string::npos){
				cout<<t<<endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1184
use std::str::FromStr;
use std::io::stdin;

fn main() {
    let vec = read_vec::<String>();
    let mut count = 0;
    if vec[0] == vec[1] { count += 1; }
    if vec[1] == vec[2] { count += 1; }
    if vec[2] == vec[0] { count += 1; }
    println!("{}", if count == 1 { "Yes" } else { "No" });
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|x| x.parse().ok().unwrap()).collect()
}

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

cnt4 = 0
cnt2 = 0
for a in A:
    if a % 4 == 0:
        cnt4 += 1
    elif a % 2 == 0:
        cnt2 += 1

if (n - max(0, cnt2 - 1)) // 2 <= cnt4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
	
	public static final int INF = Integer.MAX_VALUE / 2 - 1;
	
	public static class Walk implements Comparable<Walk> {
		int node, cost;

		public Walk(int node, int cost) {
			super();
			this.node = node;
			this.cost = cost;
		}

		@Override
		public int compareTo(Walk arg0) {
			return this.cost < arg0.cost ? -1 : this.cost > arg0.cost ? 1 : 0;
		}
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		ArrayList<ArrayList<Integer>> adj_cost = new ArrayList<ArrayList<Integer>>();		
		ArrayList<ArrayList<Integer>> adj_node = new ArrayList<ArrayList<Integer>>();		
		for(int i = 0; i < n; i++){
			adj_cost.add(new ArrayList<Integer>());
			adj_node.add(new ArrayList<Integer>());
		}
		
		for(int i = 0; i < n; i++){
			final int u = sc.nextInt();
			
			final int k = sc.nextInt();
			
			for(int j = 0; j < k; j++){
				final int v = sc.nextInt();
				final int c = sc.nextInt();
				
				adj_cost.get(u).add(c);
				adj_node.get(u).add(v);
			}
		}
		
		int[] times = new int[n];
		Arrays.fill(times, INF);
		times[0] = 0;
		
		PriorityQueue<Walk> queue = new PriorityQueue<Walk>();
		queue.add(new Walk(0, 0));
		
		while(!queue.isEmpty()){
			final Walk walk = queue.poll();
			final int cur_node = walk.node;
			final int cur_cost = walk.cost;
			
			if(times[cur_node] > cur_cost){
				continue;
			}
			
			final int size = adj_node.get(cur_node).size();
			for(int i = 0; i < size; i++){
				final int next = adj_node.get(cur_node).get(i);
				final int next_cost = cur_cost + adj_cost.get(cur_node).get(i);
				
				if(times[next] <= next_cost){
					continue;
				}else{
					times[next] = next_cost;
					queue.add(new Walk(next, next_cost));
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(i + " " + times[i]);
		}
		
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public void close() throws IOException {
			br.close();
		}
	}

}

Measured memory_bytes: 78328
#include <iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
typedef long long int ll;
using namespace std;
typedef pair<int64_t,int64_t> P;

int main(){
    ll H,W,N;
    cin >> H >> W >> N;
    
    map<P,int64_t> mp;
    map<P,int64_t>::iterator itrr;
    
    for(int n=0;n<N;n++){
        int a,b;
        cin >> a >> b;
        
        for(int i = -1;i <= 1;i++){
            for(int j = -1;j <= 1;j++){
                
                if( (a+i >= 2 && a+i <= H-1) && (b+j >= 2 && b+j <= W-1) ){
                    itrr = mp.find(P(a+i , b+j));
                    if(itrr != mp.end()){
                        itrr->second += 1;
                    }else{
                        mp[P(a+i,b+j)] = 1;
                    }
                }
                
            }
        }
        
    }
    
    int64_t ans[10]={};
    map<P,int64_t>::iterator itr;
    for(itr = mp.begin();itr != mp.end(); ++itr){
        ans[itr->second] += 1;
    }
    ans[0]=(H-2)*(W-2);
    for(int i=1;i<=9;i++){
        ans[0] -= ans[i];
    }
    for(int i=0;i<9;i++){
        cout << ans[i] << "\n";
    }
    cout << ans[9] << endl;
    return 0;
}


Measured memory_bytes: 56448
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<set>
#include<algorithm>
#include<map>
#include<ctime>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int maxn = 209;
const int inf = 100000009;
const ll mod = 1e9 + 7;
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}
int main()
{
	int a, b;
	cin >> a >> b;
	ll tmp = 1ll * a*b;
	cout << tmp / gcd(a, b);
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
/// my holy template
# define F first    
# define S second
# define mp make_pair
# define pii pair<int,int>         
/// eveything goes according to plan
# define long long long  
# define pb push_back
# define sz(a) (int)(a.size())
/// countdown BEGAN. 10 , 9 , 8 ...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right     

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 9223372036854775807;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
int cnt[Sz];

int n;     
                              
int main() 
{
  Read_rap ();
  cin >> n;
  for (int i = 1;i <= n;i ++) {
    int x;  cin >> x;
    if (x)  cnt[x - 1] ++;
    cnt[x] ++;
    cnt[x + 1] ++;
  }    
  int ans = 0;
  for (int i = 0;i <= 1e5 + 1;i ++)
    ans = max (ans, cnt[i]);
  cout << ans;
  return 0;
} 










// Coded by Z...

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int n;
    cin >> n;

    int minus_count = 0;
    vector<ll> abs_a(n);
    rep(i, n) {
        int x;
        cin >> x;
        if (x < 0)minus_count++;
        abs_a[i] = abs(x);
    }

    if (minus_count % 2 == 0) {
        cout << accumulate(ALL(abs_a), 0ll) << endl;
        return;
    }

    ll abs_min = *min_element(ALL(abs_a));
    cout << accumulate(ALL(abs_a), 0ll) - (abs_min * 2) << endl;
    return;

}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

void Main() {
    char X, Y;
    cin >> X >> Y;
    if (X - Y > 0) {
        cout << ">" << endl;
    }
    else if (X - Y < 0) {
        cout << "<" << endl;
    }
    else {
        cout << "=" << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int counts = 1,maxn = -INF;
int head[MAXN];
struct node{
	int to;
	int next;
	int color;
}edge[MAXN];

void addedge(int a,int b)
{	
	edge[counts].to = b;
	edge[counts].color = 0;
	edge[counts].next = head[a];
	head[a] = counts++;
}

void dfs(int u,int c)
{
	int tmp = 1;
	for(int i = head[u];i != 0;i = edge[i].next){
		int v = edge[i].to;
		if(tmp == c)
			tmp++;
		edge[i].color = tmp;
		maxn = max(maxn,tmp);
		dfs(v,tmp);
		tmp++;
	}
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		addedge(a,b);
	}
	dfs(1,0);
	printf("%d\n",maxn);
	for(int i = 1;i < counts;i++){
		printf("%d\n",edge[i].color);
	}
	return 0;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

void solve() {
  vector<vector<int>> A(3, vector<int>(3));
  vector<vector<bool>> B(3, vector<bool>(3, false));
  cin >> A;
  int N;
  cin >> N;
  vector<int> b(N);
  cin >> b;
  for (int v : b) {
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (A[i][j] == v) B[i][j] = true;
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    bool judge = true;
    for (int j = 0; j < 3; j++) { judge &= B[i][j]; }
    if (judge) {
      cout << "Yes" << endl;
      return;
    }
  }
  for (int i = 0; i < 3; i++) {
    bool judge = true;
    for (int j = 0; j < 3; j++) { judge &= B[j][i]; }
    if (judge) {
      cout << "Yes" << endl;
      return;
    }
  }
  {
    bool judge = true;
    for (int i = 0; i < 3; i++) { judge &= B[i][i]; }
    if (judge) {
      cout << "Yes" << endl;
      return;
    }
  }
  {
    bool judge = true;
    for (int i = 0; i < 3; i++) { judge &= B[i][2 - i]; }
    if (judge) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

inline void down(int &x,const int &y){if(x>y)x=y;}
const int maxn = 1100;
const int maxv = 5100;

int n;
struct edge{int y,nex;}a[maxn<<1]; int len,fir[maxn];
inline void ins(const int x,const int y){a[++len]=(edge){y,fir[x]};fir[x]=len;}

int f[maxn],w[maxn],g[2][maxv];
void clear(const int now){for(int i=0;i<maxv;i++) g[now][i]=inf;}
bool dp(const int x)
{
    if(!fir[x]) {f[x]=0;return true;}
    for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y) 
        if(!dp(y))return false;
    int now=1; clear(now); g[now][0]=0;
    for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y) 
    {
        now=!now; clear(now);
        for(int i=0;i<=w[x];i++)
        {
            if(i>=w[y]) down(g[now][i],g[!now][i-w[y]]+f[y]);
            if(i>=f[y]) down(g[now][i],g[!now][i-f[y]]+w[y]);
        }
    }
    int cc=inf;
    for(int i=0;i<=w[x];i++) down(cc,g[now][i]);
    if(cc==inf) return false;
    f[x]=cc;
    return true;
}

int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int x; scanf("%d",&x);
        ins(x,i);
    }
    for(int i=1;i<=n;i++) scanf("%d",&w[i]);

    if(!dp(1)) puts("IMPOSSIBLE");
    else puts("POSSIBLE");

    return 0;
}

Measured memory_bytes: 384
def main():
    n = int(raw_input())
    a = [int(x) for x in raw_input().split()]
    if n == 1:
        print(1)
        return
    c = cmp(a[0], a[1])
    ans = 1
    for i in xrange(2, n):
        nc = cmp(a[i - 1], a[i])
        if nc == 0:
            continue
        if c == 0:
            c = nc
        elif nc != c:
            c = 0
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 11832
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)

t=1
# t=int(input())
for _ in range(t):
    n=L()[0]
    if n%1000==0:
        print(0)
        exit()

    print(1000-n%1000)

Measured memory_bytes: 10608
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define eb emplace_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3+5;
const lli INF = 1e18;
const lli MOD = 1e6+3;

bool mm[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)mm[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!mm[i])for(int j = i*i; j<N; j+=i)mm[j]=1;
	for(int i = 3; i<N; i+=2)if(!mm[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

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

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7

int n,m,k;
vector<string>s;
lli bck(int r, int c){
	int x = 0;
	fore(i,0,n)fore(j,0,m)if((r & 1<<i) and (c& 1<<j) and s[i][j]=='#')x++;
	//cout<<r<<" "<<c<<" "<<x<<ENDL;
	if(x==k)return 1;
	return 0;
}

int main(){_
	cin>>n>>m>>k;
	s=vector<string>(n);
	fore(i,0,n)cin>>s[i];
	lli res = 0;
	fore(i,0,1<<n)fore(j,0,1<<m)res+=bck(i,j);
	cout<<res<<ENDL;

}


Measured memory_bytes: 3684
/**
 * Title:
 * Url:
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long

int main() {

    int N; cin >> N;
    vector<pair<int, int>> a(N), b(N);
    for(int i=0; i<N; i++) {
        int ax, ay; cin >> ax >> ay;
        a[i] = pair<int, int>(ax, ay);
    }
    for(int i=0; i<N; i++) {
        int bx, by; cin >> bx >> by;
        b[i] = pair<int, int>(by, bx);
    }
    int ans = 0;
    sort(a.begin(), a.end(), std::greater<pair<int, int>>());
    sort(b.begin(), b.end());
    for(int i=0; i<N; i++) {
        int bx = b[i].second;
        int by = b[i].first;
        for(int j=0; j<a.size(); j++) {
            if(by>=a[j].second&bx>=a[j].first) {
                ans++;
                a.erase(a.begin()+j);
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    n,m = map(int,ipt().split())
    way = [[] for i in range(n+1)]
    for i in range(m):
        l,r,d = map(int,ipt().split())
        way[l].append((r,d))
        way[r].append((l,-d))
    q = []

    pl = [10**18]*(n+1)
    for i in range(1,n+1):
        if pl[i] != 10**18:
            continue
        q.append(i)
        pl[i] = 0
        while q:
            qi = q.pop()
            pq = pl[qi]
            for j,dj in way[qi]:
                if pl[j] == 10**18:
                    pl[j] = pq+dj
                    q.append(j)
                elif pl[j] != pq+dj:
                    print("No")
                    exit()
    print("Yes")

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 108800
import itertools
import math

k = int(input())

l = list(itertools.combinations_with_replacement(list(range(1, k+1)), 3))
ans = 0

for i in l:
    a, b, c = i
    if a == b == c:
        ans += math.gcd(math.gcd(a, b), c)
    elif (a == b) or (b == c):
        ans += 3 * (math.gcd(math.gcd(a, b), c))
    else:
        ans += 6 * (math.gcd(math.gcd(a, b), c))

print(ans)


Measured memory_bytes: 105388
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll ans = 0;
    ll mul = 1;
    ll m;

    while(H > 0){
        ans += mul;
        mul *= 2;
        H /= 2;
    }

    cout << ans << endl;

    return 0;
}

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

struct three{
    ll a;
	ll b;
	ll c;
};
int main(){
    ll n;
    cin>>n;
    three d[n+1],mas[n+1];
    for(ll k=1;k<=n;k++){
        ll x,y,z;
        cin>>x>>y>>z;
        mas[k].a=x;
        mas[k].b=y;
        mas[k].c=z;
    }
    d[1]=mas[1];
    for(ll k=2;k<=n;k++){
        d[k].a=mas[k].a+max(d[k-1].b,d[k-1].c);
        d[k].b=mas[k].b+max(d[k-1].c,d[k-1].a);
        d[k].c=mas[k].c+max(d[k-1].a,d[k-1].b);
    }
    cout<<max(max(d[n].a,d[n].b),d[n].c);
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
LL rui[1000000];
int main(){
    CIN(N);
    V<LL> vec;
    REP(a,N){
      CIN(b);vec.pb(b);
      rui[a+1]+=rui[a]+b;
    }
    LL ans = LINF;
    FOR(a,1,N){
       ans = min(ans,abs(rui[N]-(rui[a]*2)));
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 3444
S=input()
n=len(S)
b=[]
a=[]
for i in range(n-1):
    if S[i]=='R' and S[i+1]=='L':
        b.append(i)
def lb(x):
    l=0;r=len(b)-1
    re=0
    while r>=l:
        mid=(l+r)//2
        if b[mid]>=x:
            re=b[mid]
            r=mid-1
        else:
            l=mid+1
    return re
def ub(x):
    l=0;r=len(b)-1
    re=0
    while r>=l:
        mid=(l+r)//2
        if b[mid]<=x:
            re=b[mid]
            l=mid+1
        else:
            r=mid-1
    return re
for i in range(n):
    if S[i]=='R':
        a.append(lb(i))
    else:
        a.append(ub(i))
def Dis(x):
    if S[x]=='R':
        return a[x]-x
    else:
        return x-a[x]-1
dis=list(map(Dis,range(0,n)))
ans=[0 for i in range(0,n)]
for i in range(n):
    if S[i]=='R':
        if (dis[i]&1)==1:
            ans[a[i]+1]+=1
        else:
            ans[a[i]]+=1
    else:
        if (dis[i]&1)==1:
            ans[a[i]]+=1
        else:
            ans[a[i]+1]+=1
for i in ans:
    print(i,end=' ')


Measured memory_bytes: 9492
package main

import "fmt"

func gcd(a int, b int) int {
	for (b > 0) {
		var A int = a
		a = b
		b = A % b
	}
	return a
}

func lcm(a int, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	var X int
	fmt.Scan(&X)
	fmt.Println(lcm(360, X) / X)
}


Measured memory_bytes: 1764
import numpy as np
L,R = (int(x) for x in input().split())

if R - L > 3000:
  print(0)
  exit()
  
x = np.arange(L,R+1,dtype=np.int64)
y = x[:,None] * x[None,:] % 2019
for i in range(len(x)):
  y[i,i] = 3000
answer = y.min()
print(answer)


Measured memory_bytes: 76256
#include<stdio.h>
#include<string.h>

int main()
{
   int a[100],temp;
   for(int i=0;i<3;i++)
   {
       scanf("%d",&a[i]);
   }
   for(int i=0;i<3;i++)
   {
       for(int j=i+1;j<3;j++)
       {
           if(a[i]>a[j])
           {
               temp=a[i];
               a[i]=a[j];
               a[j]=temp;
           }
       }
   }
   int sum=0;
   for(int i=1;i<3;i++)
   {
       sum+=(a[i]-a[i-1]);
   }
   printf("%d\n",sum);
   return 0;

}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,m;
 cin>>n>>m;

 vector<ll>vec(n,0);
 ll s,c;
 rep(i,0,m){
  cin>>s>>c;
  //cout<<s<<" "<<c<<endl;
  if((n!=1&&s==1&&c==0)||(vec[s-1]!=0&&vec[s-1]!=c)){
   puts("-1");return 0;
  }
  vec[s-1]=c;
 }
 if(n!=1&&vec[0]==0)vec[0]=1;
 rep(i,0,n)cout<<vec[i];
 pnn;
 return 0;}



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

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

    int s1 = atoi(s.substr(0,2).c_str());
    int s2 = atoi(s.substr(2,2).c_str());
    string ans = "";

    if ((s1 >= 1 && s1 <= 12) && (s2 >= 1 && s2 <= 12)) {
        ans = "AMBIGUOUS";
    } else if (s2 >= 1 && s2 <= 12) {
        ans = "YYMM";
    } else if (s1 >= 1 && s1 <= 12) {
        ans = "MMYY";
    } else {
        ans = "NA";
    }
    cout << ans << endl;

}




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

int main(void){
    int n;

    cin >> n;
    cout << fixed << setprecision(10) << (n % 2 == 0? n / 2 / (double) n : (n + 1) / 2 / (double) n) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  st s;
  	ci(s);
  ll a=s.sz;
  cout<<s[0]<<a-2<<s[a-1]<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class UnionFindTree
{
private:
    int n;
    int groupNum;       // グループの数
    vector<int> parent; // 親ノード
    vector<int> rank;   // 木の高さの上限
    vector<int> num;    // グループの要素数
    int find(int i){
        if(parent[i] == i)
            return i;
        else
            return parent[i] = find(parent[i]);
    }
public:
    UnionFindTree(int n){ // コンストラクタ
        this->n = n;
        groupNum = n;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
    }
    void unite(int a, int b){ // aとbのグループを併合
        if((a = find(a)) != (b = find(b))){
            if(rank[a] < rank[b]){
                parent[a] = b;
                num[b] += num[a];
            }
            else{
                parent[b] = a;
                if(rank[a] == rank[b])
                    ++ rank[a];
                num[a] += num[b];
            }
            -- groupNum;
        }
    }
    bool same(int a, int b){ // aとbのグループが同じかを調べる
        return find(a) == find(b);
    }
    int getNum(){ // グループの数を返す
        return groupNum;
    }
    int getNum(int a){ // aのグループの要素数を返す
        return num[find(a)];
    }
    void getGroup(vector<vector<int> >& group){ // グループ構成を返す
        map<int, int> index;
        group.clear();
        for(int i=0; i<n; ++i){
            int a = find(i);
            if(index.find(a) == index.end()){
                index[a] = group.size();
                group.resize(group.size() + 1);
            }
            group[index[a]].push_back(i);
        }
    }
};

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

    UnionFindTree uft(n);
    for(int i=0; i<2; ++i){
        vector<pair<int, int> > v(n);
        for(int i=0; i<n; ++i)
            v[i] = make_pair(x[i], i);
        sort(v.begin(), v.end());
        for(int j=0; j<n-1; ++j){
            if(v[j].first == v[j+1].first)
                uft.unite(v[j].second, v[j+1].second);
        }
        x.swap(y);
    }

    vector<vector<int> > group;
    uft.getGroup(group);
    long long ans = -n;
    for(const auto& v : group){
        set<int> sx, sy;
        for(int i : v){
            sx.insert(x[i]);
            sy.insert(y[i]);
        }
        ans += sx.size() * (long long)sy.size();
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7408
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
int n, c[100005];
vector<pair<int,int> > g[100005];
void dfs(int u,int p,int o){
	c[u] = o;
	for(pair<int,int> v: g[u])
		if(v.fi != p)
			dfs(v.fi, u, (o + v.se)%2);
}
signed main(){
	cin >> n;
	for(int i = 1 ; i < n ; i ++){
		int u, v, w;
		cin >> u >> v >> w;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	dfs(1, 0, 0);
	for(int i = 1 ; i <= n ; i ++)
		cout << c[i] << " ";
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

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

    string s;
    cin >> s;

    vector<int> pf, sf;
    int d = 1;
    for (int i = 0; i < n;) {
        if (s[i] == 'o')pf.push_back(i + 1), d++, i += c + 1;
        else if (s[i] == 'x') {
            i++;
            continue;
        }
        if (d == k + 1)break;
    }
//    for(auto x: pf)cout << x << endl;
    d = k;
    for (int i = n - 1; i >= 0;) {
        if (s[i] == 'o')sf.push_back(i + 1), d--, i -= (c + 1);
        else if (s[i] == 'x') {
            i--;
            continue;
        }
        if (d == 0)break;
    }
//    for(auto x: sf)cout << x << endl;

    reverse(sf.begin(), sf.end());
    for (int i = 0; i < sf.size(); i++) {
        if(sf[i] == pf[i])cout << sf[i] << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    while (t--)
        solve();
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL memo[2][51][51][51];
LL fact[2010], facti[2010];

LL powm(LL x, LL y, LL m){
  if(y == 0) return 1;
  return powm(x*x%m, y/2, m) * (y%2==0?1:x) % m;
}

LL inv(LL x, LL m){
  return powm(x,m-2,m);
}

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

  fact[0] = facti[0] = 1;
  REP(i,2010-1){
	fact[i+1] = fact[i] * (i+1) % MOD;
	facti[i+1] = inv(fact[i+1], MOD);
  }

  int A, T, G, C;
  cin >> A >> T >> G >> C;

  int Q;
  cin >> Q;
  map<string,int> id;
  VS rule_(Q);
  REP(i,Q){
	string line;
	cin >> line;
	id[line.substr(0,SZ(line)-1)] = i;
	getline(cin, line);
	rule_[i] = line;
  }

  VVI rule(Q);
  VVI cnt(Q, VI(16));
  REP(i,Q){
	stringstream ss(rule_[i]);
	string var;
	while(ss >> var){
	  if(var[0] == '['){
		int b = 0;
		for(char c: var){
		  if(c == 'A') b |= 1;
		  if(c == 'T') b |= 2;
		  if(c == 'G') b |= 4;
		  if(c == 'C') b |= 8;
		}
		cnt[i][b]++;
	  }
	  else{
		rule[i].PB(id[var]);
	  }
	}
  }

  int UB = A + T + G + C;
  for(int i=Q-1;i>=0;--i){
	for(int x: rule[i])
	  REP(b,16){
		cnt[i][b] += cnt[x][b];
		mini(cnt[i][b], UB+1);
	  }
  }

  if(accumulate(ALL(cnt[0]), 0) > UB){
	cout << 0 << endl;
	return 0;
  }

  fill((LL*)memo, (LL*)memo+2*51*51*51, 0);
  int crt = 0, nxt = 1, n = 0;
  memo[crt][0][0][0] = 1;
  REP(b,16){
	if(!cnt[0][b]) continue;

	REP(i,cnt[0][b]){
	  fill((LL*)memo[nxt], (LL*)memo[nxt]+51*51*51, 0);

	  REP(a,A+1) REP(t,T+1) REP(g,G+1){
		int c = n - a - t - g;
		if(c < 0 || c > C) continue;
		if((b>>0&1) && a+1 <= A) (memo[nxt][a+1][t][g] += memo[crt][a][t][g]) %= MOD;
		if((b>>1&1) && t+1 <= T) (memo[nxt][a][t+1][g] += memo[crt][a][t][g]) %= MOD;
		if((b>>2&1) && g+1 <= G) (memo[nxt][a][t][g+1] += memo[crt][a][t][g]) %= MOD;
		if((b>>3&1) && c+1 <= C){
		  (memo[nxt][a][t][g] += memo[crt][a][t][g]) %= MOD;
		}
	  }
	  ++n;
	  swap(crt, nxt);
	}
  }
  cout << memo[crt][A][T][G] << endl;

  return 0;
}

Measured memory_bytes: 5344
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
typedef long long ll;
const ll maxn = 1e6+10;
const ll inf = 1e16;

ll N;
int main(){
//    freopen("in.txt", "r", stdin);
    cin>>N;
    ll sum = N*(1+N)/2;
    ll res = sum-N;
    cout<<res<<endl;
    

    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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(){
  string S;
  cin>>S;
  deque<char> dS(S.size());
  for(int i=0; i<S.size(); ++i) dS[i]=S[i];
  
  int Q;
  cin>>Q;
  int rev=0;
  for(int i=0; i<Q; ++i){
    int type;
    cin>>type;
    if(type==2){
      int f;
      char c;
      cin>>f>>c;
      --f;
      if(rev) f=1-f; // 反転状態だったら、フラグを反転
      if(f==0) dS.push_front(c);
      else dS.push_back(c);
    }
    else rev=1-rev;
  }
  if(rev) reverse(dS.begin(),dS.end());
  for(auto c:dS) cout<<c;
  cout<<endl;
  return 0;
}

Measured memory_bytes: 4012
NW = list(map(int, input().split()))
wv = []
for i in range(NW[0]):
    wv.append(list(map(int, input().split())))

dp = [[float("inf")] * 10**3*(NW[0]+1) for i in range(NW[0]+1)]
dp[0][0] = 0
for i in range(len(dp)):
    for sum_v in range(len(dp[i])):
        try:
            if sum_v-wv[i][1]>=0:
                dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v-wv[i][1]] + wv[i][0])
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])
        except:
            continue

for sum_v in range(len(dp[i])):
    if dp[NW[0]][sum_v] <= NW[1]:
        res = sum_v

print(res)

Measured memory_bytes: 313720
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

int main(void) {
    int64_t width, height;
    cin >> width >> height;
    int64_t x, y;
    cin >> x >> y;
    // vertical
    bool flag = (x * 2 == width && y * 2 == height);
    double ans = (double)width*height/2;
    printf("%.10lf %d\n", ans, flag);
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
typedef long long lint;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define INF 1e18

signed main()
{
	int N,K;
	cin >> N >> K;
	cout << N - K + 1 << endl;

	return 0;
}

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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>

typedef long long ll;

int main() {
  int N, cnt = 0;
  double ans = 0;
  cin >> N;
  vi X(N, 0), Y(N, 0);
  vi perm(N);
  for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
  for (int i = 0; i < N; i++) perm[i] = i;
  do {
    for (int i = 0; i < N - 1; i++) {
      int x_diff = X[perm[i]] - X[perm[i + 1]];
      int y_diff = Y[perm[i]] - Y[perm[i + 1]];
      ans += sqrt(x_diff * x_diff + y_diff * y_diff);
    }
    cnt++;
  } while (next_permutation(perm.begin(), perm.end()));
  printf("%.12f", ans / cnt);
  return 0;
}

Measured memory_bytes: 256