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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  string s;
  cin >> s;
  int ans=s.length();
  int hasi=0;
  bool hatu=true;
  for(int i=0;i<s.length()-1;i++){
    if(s[i]=='S'){
      for(int j=max(i+1,hasi);j<s.length();j++){
        if(s[j]=='T'){
          ans-=2;
          s[j]='*';
          hasi=j+1;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static int mod =1000000007;
	public static void main(String[] args) {
		int N=sc.nextInt();
		int M=sc.nextInt();
		int a[]=new int[M];
		int an=0;
		for(int i=0;i<M;i++) {
			a[i]=sc.nextInt();
			an+=a[i];
		}
		if(an>N) {
			p(-1);
		}else {
			p(N-an);
		}
		
		 
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 46376
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>

using namespace std;

#define rep(i,N) for (int i = 0; i < N; i++)
#define llong long long
#define ldouble long double


llong x;

bool isPrime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (!(num%2)) return false;

    for (int i = 3; i*i <= num; i++) {
        if (!(num%i)) return false;
    }

    return true;
}

int main() {
    cin >> x;
    while(!isPrime(x)) {
        x++;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			PriorityQueue<Player> pq = new PriorityQueue<Player>();
			char[][] map = new char[h][w];
			for (int i = 0; i < h; i++) {
				map[i] = scanner.next().toCharArray();
				for (int j = 0; j < w; j++) {
					if (map[i][j] != '#' && map[i][j] != '.'
							&& map[i][j] != 'X') {
						char c = map[i][j];
						int dir = c == 'W' ? 0 : c == 'S' ? 1 : c == 'E' ? 2
								: 3;
						map[i][j] = 'P';
						pq.add(new Player(i, j, dir));
					}
				}
			}
			String ans = "NA";
			int step = 1;
			while (step <= 180) {
				PriorityQueue<Player> next = new PriorityQueue<Player>();
				pl: while(!pq.isEmpty()) {
					Player player = pq.poll();
					for (int k = 3; k < 7; k++) {
						int y = player.y;
						int x = player.x;
						int dir = player.dir;
						int ny = y + move[(k + dir) % 4][0];
						int nx = x + move[(k + dir) % 4][1];
						if (map[ny][nx] == '.' || map[ny][nx] == 'X') {
							player.dir = (k + dir) % 4;
							player.ny = ny;
							player.nx = nx;
							next.add(player);
							continue pl;
						}
					}
					player.b = false;
					next.add(player);
				}
				while (!next.isEmpty()) {
					Player player = next.poll();
					if (!player.b) {
						player.b = true;
						next.add(player);
					} else {
						int y = player.y;
						int x = player.x;
						int ny = player.ny;
						int nx = player.nx;
						map[y][x] = '.';
						if (map[ny][nx] == 'X') {
							map[ny][nx] = 'x';
							continue;
						}
						if (map[ny][nx] == '.') {
							map[ny][nx] = 'P';
							player.y = ny;
							player.x = nx;
							pq.add(player);
						} else {
							map[y][x] = 'P';
							pq.add(player);
						}

					}

				}
				if (pq.isEmpty()) {
					ans = String.valueOf(step);
					break;
				}
				pq.addAll(next);
				for (int i = 0; i < h; i++)
					for (int j = 0; j < w; j++)
						if (map[i][j] == 'x')
							map[i][j] = 'X';
				step++;
			}
			System.out.println(ans);

		}
	}

	int[][] move = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };

	class Player implements Comparable<Player> {
		int y;
		int x;
		int dir;
		int ny;
		int nx;
		boolean b = true;

		public Player(int y, int x, int dir) {
			super();
			this.y = y;
			this.x = x;
			this.dir = dir;
		}

		@Override
		public int compareTo(Player o) {
			return this.dir - o.dir;
		}

	}
}

Measured memory_bytes: 25092
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    string s; cin >> s;
    vector<string> list = {"maerd", "esare", "remaerd", "resare"};
    string t = s;
    reverse(t.begin(), t.end());
    for(ll i = 0; i < t.length(); ){
        bool z = false;
        for(auto j : list){
            string sub = t.substr(i, j.length());
            if(sub == j){
                i += j.length();
                z = true;
                break;
            }
        }
        if(!z){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3852
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#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 <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  cin >> n;
  vector<PI> pool;
  REP(i, 0, n - 1) {
    if (i % 2 == 1) {
      pool.push_back(PI(0, i));
      pool.push_back(PI(i, 0));
    }
  }
  REP(i, 0, n) {
    if ((i + n - 1) % 2 == 1) {
      pool.push_back(PI(n - 1, i));
      pool.push_back(PI(i, n - 1));
    }
  }
  for (int j = 1; j < n - 1; j += 3) {
    REP(i, 1, n - 1) {
      if ((i + j) % 2 == 1) {
	pool.push_back(PI(i, j));
      }
    }
  }
  cout << pool.size() << endl;
  REP(i, 0, pool.size()) {
    cout << pool[i].first << " " << pool[i].second << endl;
  }
}


Measured memory_bytes: 2928
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n;
	String[] lines;

	void run(){
		n=sc.nextInt();
		sc.nextLine();
		lines=new String[n];
		for(int i=0; i<n; i++){
			lines[i]=sc.nextLine();
		}
		solve();
	}

	void solve(){
		for(int i=0; i<n; i++){
			lines[i]=lines[i].substring(0, lines[i].length()-1);
		}
		int[] next=new int[n];
		for(int i=0; i<n; i++){
			String[] ss=lines[i].split(" ");
			if(ss.length==2){
				String label=ss[1];
				for(int j=0; j<n; j++){
					if(lines[j].equals(label)){
						next[i]=j;
					}
				}
			}else{
				next[i]=i+1;
			}
		}
		int[] d=new int[n+1];
		fill(d, INF);
		d[0]=0;
		LinkedList<Integer> que=new LinkedList<Integer>();
		que.addLast(0);
		for(; !que.isEmpty();){
			int v=que.poll();
			if(v==n){
				continue;
			}
			if(d[v]<d[next[v]]){
				d[next[v]]=d[v];
				que.addFirst(next[v]);
			}
			if(d[v]+1<d[v+1]){
				d[v+1]=d[v]+1;
				que.addLast(v+1);
			}
		}
//		debug(d);
		println(d[n]+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 18484
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;



int32_t main() {

    simplify
    int l,d,m;
    cin>>l>>d>>m;

    int ans=0;
    for(int i=l;i<=d;i++){
        if(i%m==0)ans++;
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 3608
#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

#define VAL_MAX 100
int main(void) {
    int num; int rem;
    cin >> num >> rem;
    vector<int> arr(num);
    cins(arr);

    vector<vector<int64_t>> dp(num+1, vector<int64_t>(num*VAL_MAX+1));
    dp[0][0] = 1;
    for(int i = 1; i <= num; i++) {
        for(int j = 0; j <= num*VAL_MAX; j++) {
            int val = arr[i-1];
            dp[i][j] += dp[i-1][j];
            if(j >= val) dp[i][j] += dp[i-1][j-val];
        }
    }
    int64_t ans = 0;
    for(int i = rem; i <= num*VAL_MAX; i+=2) {
        debug("%d -> %lld\n", i, dp[num][i]);
        ans += dp[num][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            sS = sS.Replace("2017", "2018");

            // 出力
            Console.WriteLine("{0}", sS.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;

int main() {
  string S;
  cin>>S;
  
  int ans=0;
  for(int i=0;i<S.size();++i){
    int count=0;
    for(int j=i;j<S.size();++j){
      if(S[j]=='A'||S[j]=='C'||S[j]=='G'||S[j]=='T')
        ++count;
      else
        break;
    }
    
    ans=max(ans,count);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 4557430888798830399
#define int long long
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N = 5005;
struct cont {
	int h, p;
	bool operator<(const cont &rhs) const {
		return h + p < rhs.h + rhs.p;
	}
} c[N];
int n, dp[N][N];
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n) cin >> c[i].h >> c[i].p;
	sort(c, c + n);
	memset(dp, 63, sizeof(dp));
	dp[0][0] = 0;
	fw (i, 0, n) fw (j, 0, i + 1) if (dp[i][j] != INF) {
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		if (dp[i][j] <= c[i].h) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + c[i].p);
	}
	bw (i, n + 1, 0) if (dp[n][i] != INF) {
		cout << i;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 196096
import sys
import math

class cin():
    def getInt():
        return int(sys.stdin.readline().rstrip())
    def getString():
        return sys.stdin.readline().rstrip()

N = cin.getInt()
A = [list(map(int,cin.getString().split())) for i in range(N - 1)]

for i in range(N):
    t = 0
    for j in range(i,N - 1):
        if t <= A[j][1]:
            t = A[j][1] + A[j][0]
        else:
            t = -(-t // A[j][2]) * A[j][2] + A[j][0]
    print(t)

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

void solve(int N, vector<int> A)
{
    sort(A.begin(), A.end());
    int l = 0, r = 1;
    for (int i = 1; i < N - 1; i++)
    {
        if (A.at(i) >= 0)
            break;
        l++;
        r++;
    }
    int res = 0;
    for (int i = 0; i <= l; i++)
        res -= A.at(i);
    for (int i = r; i < N; i++)
        res += A.at(i);
    cout << res << endl;

    int current;
    if (r == N - 1)
    {
        cout << A.at(r) << " " << A.at(l) << endl;
        current = A.at(r) - A.at(l);
    }
    else
    {
        cout << A.at(l) << " " << A.at(r) << endl;
        current = A.at(l) - A.at(r);
    }
    l--;
    r++;
    while (r < N)
    {
        if (r == N - 1)
        {
            cout << A.at(r) << " " << current << endl;
            current = A.at(r) - current;
        }
        else
        {
            cout << current << " " << A.at(r) << endl;
            current -= A.at(r);
        }
        r++;
    }
    while (l >= 0)
    {
        cout << current << " " << A.at(l) << endl;
        current -= A.at(l);
        l--;
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>

int main() {
	int n;
	long long ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0)
			ans += i;
	}

		printf("%lld",ans);
	
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
int main() 
{
  int n;
  cin >> n;
  long long h[n], dp[n];
  rep(i,n) cin >> h[i];
  rep(i,n) dp[i] = INF;
  dp[0] = 0;
  rep(i,n){
    dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1]);
    dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2]);
  }  
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
a = list(map(int, input().split()))
sum_list = []
k = 0
for i in range(-100, 101):
    sum_list.append(0)
    for j in range(N):
        sum_list[k] += pow(i - a[j], 2)
    k += 1
print(min(sum_list))


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

int main()
{
  	int n=0;
  	double ans=0;
  	double x=0;
  	string str;
  	cin>>n;
  	for(int i=0 ; i<n ; ++i)
    {
    	cin>>x>>str;
      	ans+=(str=="BTC"?x*380000:x);
    }
  	cout<<fixed<<ans<<endl;
	return 0;
}

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

int main() {
	string a,b,c;
	cin >> a >> b >> c;
	if (a.back() == b.front() && b.back() == c.front()){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int w,h;
char map[200][200];
class Node{
public:
	int x,y;
	int c;
	Node(int _x,int _y,int _c):x(_x),y(_y),c(_c){

	}
};
void show(){
	for(int i=0;i<h*2-1;i++){
		for(int j=0;j<w*2-1;j++)cout<<map[i][j];
		cout<<endl;
	}
	cout<<endl;
}
bool visited[200][200];
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
int bfs(){
	for(int i=0;i<100;i++)fill(visited[i],visited[i]+100,false);
	queue<Node> q;
	q.push(Node(0,0,1));
	visited[0][0]=true;
	int gw=2*w-2;
	int gh=2*h-2;
	while(!q.empty()){
		Node cur=q.front();q.pop();
//		map[cur.y][cur.x]='1';
		if(cur.x==gw&&cur.y==gh)return cur.c;
		for(int i=0;i<4;i++){
			int nx=cur.x+dx[i];
			int ny=cur.y+dy[i];
			if(nx<0||ny<0||nx>gw||ny>gh||map[ny][nx]=='1')continue;
			nx=nx+dx[i];
			ny=ny+dy[i];
			if(nx<0||ny<0||nx>gw||ny>gh||map[ny][nx]=='1')continue;
			map[ny][nx]='1';
//			if(visited[ny][nx])continue;
//			visited[ny][nx]=true;
			q.push(Node(nx,ny,cur.c+1));
		}
	}
	return 0;
}
void solve(){
	cout<<bfs()<<endl;
}
int main(){
	while(cin>>w>>h&&(w||h)){
		for(int i=0;i<100;i++)for(int j=0;j<100;j++)map[i][j]='0';
		int hline=h*2-1;
		for(int i=0;i<hline;i++){
			if(i%2){
				for(int j=0;j<w;j++)cin>>map[i][2*j];
			}
			else {
				for(int j=0;j<w-1;j++)cin>>map[i][1+2*j];

			}
		}
//		show();
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
<?php
list($S)=sscanf(trim(fgets(STDIN)),"%s");
if($S != strrev($S)){
    printf("No");
    exit;
}
if (substr($S,0,((strlen($S)-1-1)/2)+1) != strrev(substr($S,0,((strlen($S)-1-1)/2+1)))){
    printf("No");
    exit;
}

if(substr($S,((strlen($S)+3)/2)-1) != strrev(substr($S,((strlen($S)+3)/2)-1))){
    printf("No");
    exit;
}
printf("Yes");

Measured memory_bytes: 4728
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;
using PP = pair<pair<LL, LL>, int>;
vector<string>SS;

int main() {
	int N;
	cin >> N;
	vector<PP>vec;
	LL sum = 0;
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		LL a = 0, x = 0;
		for (char c : S) {
			if (c == '(')x++;
			else x--;
			a = min(a, x);
		}
		a = max(a, a - x);
		vec.push_back({ {a,x},i });
		sum += x;
		SS.push_back(S);
	}
	sort(vec.begin(), vec.end(), [](const PP& p1, const PP& p2) {
		if (p1.first.second > 0 && p2.first.second < 0) {
			return true;
		}
		if (p1.first.second < 0 && p2.first.second > 0) {
			return false;
		}
		if (p1.first.second > 0 && p2.first.second > 0) {
			return p1.first.first > p2.first.first;
		}
		if (p1.first.second < 0 && p2.first.second < 0) {
			return p1.first.first < p2.first.first;
		}
		if (p1.first.second > 0) {
			return true;
		}
		if (p1.first.second < 0) {
			return false;
		}
		if (p2.first.second > 0) {
			return false;
		}
		if (p2.first.second < 0) {
			return true;
		}
		return false;
		});
	LL now = 0;
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		for (char c : SS[vec[i].second]) {
			if (c == '(') {
				now++;
			}
			else {
				now--;
			}
			if (now < 0) {
				cout << "No" << endl;
				return 0;
			}
			if (now == 0)cnt++;
		}
	}
	if (now != 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 57916
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, M;
  std::cin >> N >> M;

  std::map<ll, ll> mac;
  std::map<ll, ll> mwa;

  for (ll i = 0; i < M; i++) {
    ll p; std::string S;
    std::cin >> p >> S;

    if (S == "AC") {
      mac[p]++;
    } else {
      if (mac.count(p) == 0) {
        mwa[p]++;
      }
    }
  }

  ll ac = static_cast<ll>(mac.size());
  ll wa = 0LL;
  std::map<ll, ll>::iterator it;
  for (it = mwa.begin(); it != mwa.end(); it++) {
    if (mac.count(it->first) > 0) {
      wa += it->second;
    }
  }

  print(ac, wa);
  return 0;
}


Measured memory_bytes: 6528
n = gets.to_i
a = []
b = []
n.times do |i|
  a[i],b[i] = gets.chomp.split(" ").map(&:to_i)
end
cnt = 0
(n-1).downto(0) do |i|
  if a[i] % b[i] != 0
    cnt += b[i] -  a[i] % b[i]
  end
  if i != 0
    a[i-1] += cnt
  end
end
puts cnt

Measured memory_bytes: 16176
/*input
5
0.42 0.01 0.42 0.99 0.42
*/
#include<bits/stdc++.h>
using namespace std;

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

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

const int MOD = 1e9+7;

int n;
long double prob[3000];
long double dp[3000][3000];




void solve(){
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> prob[i];

    // memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=i;j++){
            // if(i==0 || j==0) {
            //     dp[i][j] = 1;
            //     continue;
            // }
            // cout << i << " " << j << "\n";
            // cout << prob[i] << "\n";
            dp[i+1][j] += dp[i][j]*(1-prob[i]);
            dp[i+1][j+1] += dp[i][j]*prob[i];
            // cout << dp[i][j] << " ";
        }
        // cout << "\n";
    }

    long double ans = 0;
    for(int i=n/2+1;i<=n;i++){
        ans += dp[n][i];
    }
    cout << fixed << setprecision(16);
    cout << ans;

}

int main(){
    // FIN;   
    // test
    solve();
}

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


int main(){
    int N, L;
    cin >> N >> L;
    int ans = (L+L+N-1)*N /2;
    if(L>0) ans -= L;
    if(L+N-1<0) ans -= L+N-1;
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head = 1, tail = 0, n;

void enqueue(P x){
  strcpy(Q[tail].name, x.name);
  Q[tail].t = x.t;
  tail++;
  if(tail > n) tail = 0;
}

P dequeue(){
  P x;
  x = Q[head];
  head++;
  if(head > n) head = 0;
  return x;
}


int main(){
  int elaps = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  while(1){
    u = dequeue();
    if(u.t - q > 0){
      u.t = u.t - q;
      elaps += q;
      enqueue(u);
    }
    else{
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
      if(head == tail) break;
    }
  }

  return 0;
}



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

int main() {
    string S;
    cin >> S;
    int price = 700;
    if (S[0] == 'o') price += 100;
    if (S[1] == 'o') price += 100;
    if (S[2] == 'o') price += 100;
    cout << price << endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  ll sum = 0;
  ll INF = 1001001001;
  ll mn = INF;
  sort(x.begin(), x.end());
  for (ll i=x[0]; i<x[n-1]+1; ++i) {
    rep(j,n) sum += pow(i-x[j], 2);
    mn = min(mn, sum);
    sum = 0;
  }
  cout << mn << endl;
  
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする
 
using namespace std;
typedef long long int ll;
typedef pair< long long int , long long int> P;

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

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

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

 
int main(void){

	long long int  r,d;
	long long int x;

	cin>>r>>d>>x;

	FOR(i,1,10){
		x=r*x-d;
		cout<<x<<endl;
	}

}



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

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n), dp(n, 999999999);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i < n; ++i) {
		dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
		for (int j = 1; j <= k; ++j) {
			if (i - j < 0) break;
			dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
		}
	}
	cout << dp[n - 1] << endl;	
	cin >> n;

}

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

int main(){
    int n,x,ans;
    cin>>n>>x;
    if(n>=13){
        ans=x;
        }else if(n>=6){
        ans=x/2;
        }else{
            ans=0;
            }
        cout<<ans<<endl;
        }


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	/* 目的 : 入力の最小公倍数を求める */
	
	int a;		/* ユーザー入力A */
	int b;		/* ユーザー入力B */
	scanf("%d %d", &a, &b);

	int mul_a;			/* aにかける数 multiplier_a */
	int mul_b;			/* bにかける数 multiplier_b */
	long long int result_a;		/* aの計算結果 */
	long long int result_b;		/* bの計算結果 */
	
	mul_a = 1;
	mul_b = 1;
	result_a = a;
	result_b = b;

	while(1){
		while(result_a > result_b){
			result_b = (long long int)b * mul_b;
			++mul_b;
		}
		while(result_a < result_b){
			result_a = (long long int)a * mul_a;
			++mul_a;
		}
		if(result_a == result_b)
			break;
	}
	printf("%lld\n", result_a);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n, a;
  cin >> n >> a;
  vecint x(n);
  for (auto &e : x) {
    cin >> e;
    e -= a;
  }
  vector<map<int, ll>> dp(n + 1);
  // dp[0][x[0]]++;
  REP(i, n) {
    dp[i + 1][x[i]]++;
    REPvec(itr, dp[i]) {
      int j = itr->first;
      ll num = itr->second;
      dp[i + 1][j] += num;
      dp[i + 1][j + x[i]] += num;
    }
  }
  // REP(i, n + 1) {
  //   cout << i << "#########" << endl;
  //   REPvec(itr, dp[i]) { cout << itr->first << "  " << itr->second << endl; }
  // }
  cout << dp[n][0] << endl;
}


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

#define debug(x) cerr << #x << " = " << x << endl

const int N_MAX = 100003;
int n;

const int mod = 998244353;
int powK[N_MAX];

struct Graph {
  int m;
  vector<int> g[N_MAX];
  bool tub[N_MAX];
  int sg[N_MAX], mx, f[N_MAX];
  
  void build() {
    cin >> m;
    for (int i = 1; i <= m; ++i) {
      int x, y;
      cin >> x >> y;
      if (x > y)
        swap(x, y);
      g[x].push_back(y);
    }
    for (int x = n; x > 0; --x) {
      for (int y : g[x])
        tub[sg[y]] = 1;
      int i = 0;
      while (tub[i])
        ++i;
      sg[x] = i;
      mx = max(mx, i);
      f[i] = (powK[x] + f[i]) % mod;
      for (int y : g[x])
        tub[sg[y]] = 0;
    }
  }
}G[3];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  cin >> n;
  const int K = (long long)1e18 % mod;
  powK[0] = 1;
  for (int i = 1; i <= n; ++i)
    powK[i] = 1ll * K * powK[i - 1] % mod;
  for (int i = 0; i < 3; ++i)
    G[i].build();
  int ans = 0;
  for (int i = 0; i <= G[0].mx; ++i)
    for (int j = 0; j <= G[1].mx; ++j)
      ans = (1ll * G[0].f[i] * G[1].f[j] % mod * G[2].f[i ^ j] + ans) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15232
#include <iostream>

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

  if(a == 1) a = 15;
  if(b == 1) b = 15;
  
  if(a > b) {
    std::cout << "Alice" << std::endl;
  }else if(a < b) {
    std::cout << "Bob" << std::endl;
  }else {
    std::cout << "Draw" << std::endl;
  }
  
}

Measured memory_bytes: 256
#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> a(N);
    ll total = 0;
    Rep (i, N) {
        cin >> a[i];
        total += a[i];
    }

    ll ans = 0;
    Rep (i, N) {
        if (abs(a[i]*N - total) < abs(a[ans]*N - total)) ans = i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
include Math

a,b,h,m = gets.split(' ').map(&:to_i)

t = 60*h+m
theta_a = 2.0 * PI * t / (60*12)
theta_b = 2.0 * PI * t / 60

puts sqrt( a**2 + b**2 - 2*a*b*cos(theta_a - theta_b) )

Measured memory_bytes: 14780
#include<bits/stdc++.h>
using namespace std;
int main(){
	//#ifndef LOCAL
	//freopen("input.txt","r",stdin);
	//#endif
	ios::sync_with_stdio(false);
	cin.tie(0);


	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    string S;
    cin >> S;
    int ret = 2 * count(ALL(S), '+') - 4;
    cout << ret << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include <iostream>

// AAA=0, AA=1, A=2, B=3, C=4, D=5, E=6, NA=7
int getClass500(float t)
{
	if (t < 35.50) return 0;
	else if (t < 37.50) return 1;
	else if (t < 40.00) return 2;
	else if (t < 43.00) return 3;
	else if (t < 50.00) return 4;
	else if (t < 55.00) return 5;
	else if (t < 70.00) return 6;
	else return 7;
}

int getClass1000(float t)
{
	if (t < 71.00) return 0;
	else if (t < 77.00) return 1;
	else if (t < 83.00) return 2;
	else if (t < 89.00) return 3;
	else if (t < 105.00) return 4;
	else if (t < 116.00) return 5;
	else if (t < 148.00) return 6;
	else return 7;
}

int main()
{
	float t1, t2;
	while (std::cin >> t1 >> t2) {
		int c1 = getClass500(t1);
		int c2 = getClass1000(t2);
		int c = std::max(c1, c2);
		switch (c) {
		case 0:
			std::cout << "AAA" << std::endl; break;
		case 1:
			std::cout << "AA" << std::endl; break;
		case 2:
			std::cout << "A" << std::endl; break;
		case 3:
			std::cout << "B" << std::endl; break;
		case 4:
			std::cout << "C" << std::endl; break;
		case 5:
			std::cout << "D" << std::endl; break;
		case 6:
			std::cout << "E" << std::endl; break;
		case 7:
			std::cout << "NA" << std::endl; break;
		}
	}
	return 0;
}



Measured memory_bytes: 3200
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	// input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var N = parseInt(input, 10);
  	var aCount = 0;
  	aCount += Math.min(9, N);
  	aCount += Math.max(Math.min(999, N) - 99,0);
   	aCount += Math.max(Math.min(99999, N) - 9999,0);
	console.log('%d',aCount);
}
                   
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                String N = scan.next();
                
                if(N.equals("RRR")){
                    System.out.println(3);
                }else if(N.equals("RRS")|| N.equals("SRR")){
                    System.out.println(2);
                }else if(N.equals("SSS")){
                    System.out.println(0);
                }else{
                    System.out.println(1);
                }
                
                                 
                
                
                
        }
}

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

int main() {
  int N,M,i,a,b;
  cin>>N>>M;
  vector<vector<int> > E(N+1, vector<int>());
  for (i=0;i<M;i++) {
    cin>>a>>b;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> ans(N+1, -1);
  queue<int> R;
  ans[0]=ans[1]=0;
  R.push(1);
  while(!R.empty()) {
    int room = R.front();
    R.pop();
    for(i=0;i<E[room].size();i++) {
      if (ans[E[room][i]] < 1) {
        ans[E[room][i]] = room;
        R.push(E[room][i]);
      }
    }
  }
  for(i=2;i<=N;i++) {
    if (ans[i] < 1) break;
  }
  if (i<=N) {
    cout<<"No"<<endl;
  } else {
    cout<<"Yes"<<endl;
    for(i=2;i<=N;i++) {
      cout<<ans[i]<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 9568
(defun keisan (num1 num2 op)
    (let ((r))
        (if (string= op "-")
            (setq r (- num1 num2))
            (setq r (+ num1 num2))
        )
    r
    )
)

(let
    ((a (parse-integer (string (read-char))))
    (b (parse-integer (string (read-char))))
    (c (parse-integer (string (read-char))))
    (d (parse-integer (string (read-char))))
    (ans 0))

    (loop for i below (expt 2 3) do
        (let ((op (make-array 3 :initial-element "-")))
            (loop for j below 3 do
                (if (= (logand (ash i (- 0 j)) #b1) 1)
                    (setf (aref op j) "+")
                )
            )
            (if (= (keisan (keisan (keisan a b (aref op 0)) c (aref op 1)) d (aref op 2)) 7)
                (progn
                    (format t "~D~A~D~A~D~A~D=7" a (aref op 0) b (aref op 1) c (aref op 2) d)
                    (return)
                )
            )
        )
        
    )
)

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

int main()
{
    int a, b;

    cin >> a >> b;

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=4005;
//i_am_noob
int n,sum[maxn][3],ans=0;
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> str;
	rep1(j,3) sum[n][j]=0;
	rep3(i,n-1,0) sum[i][0]=sum[i+1][0]+(str[i]=='R'),sum[i][1]=sum[i+1][1]+(str[i]=='G'),sum[i][2]=sum[i+1][2]+(str[i]=='B');
	rep(n) rep2(j,i+1,n) if(str[i]!=str[j]){
		if(str[i]!='R'&&str[j]!='R'){
			ans+=sum[j+1][0];
			if(2*j-i<n) if(str[2*j-i]=='R') ans--;
		}
		if(str[i]!='G'&&str[j]!='G'){
			ans+=sum[j+1][1];
			if(2*j-i<n) if(str[2*j-i]=='G') ans--;
		}
		if(str[i]!='B'&&str[j]!='B'){
			ans+=sum[j+1][2];
			if(2*j-i<n) if(str[2*j-i]=='B') ans--;
		}
	}
	print1(ans);
	return 0;
}

Measured memory_bytes: 3724
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  for (int i = 1; i <= n; ++i) {
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <queue>
#include <string>
using namespace std;
using ll=long long;

const int wmax=300;
const int hmax=300;
int x[wmax*hmax+1],y[wmax*hmax+1],d[wmax*hmax+1];
int a,H,W,D;

int main(){
    cin>>H>>W>>D;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>a;
            x[a]=i;
            y[a]=j;
        }
    }
    for(int i=D+1;i<=H*W;i++){
        d[i]=d[i-D]+abs(x[i]-x[i-D])+abs(y[i]-y[i-D]);
    }
    int Q;
    cin>>Q;
    for(int i=0;i<Q;i++){
        int l,r;
        cin>>l>>r;
        cout<<d[r]-d[l]<<endl;
    }
    return 0;
}



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

int main()
{
  double a,b,c=0,s=0,l=0,h=0;
  int cd;
  cin >> a >> b >> cd;
  if(cd==90){
    s=(a*b)/2;
    c=sqrt( a*a+b*b );
    l=a+b+c;
    h=b;
  }else{
    double rad= (double) (cd*3.141592653589)/180;
    s=( a*b*sin(rad) )/2;
    c=sqrt( a*a+b*b-2*a*b*cos(rad) );
    l=a+b+c;
    h=(2*s)/a;
  }
  cout.precision(12);
  cout << showpoint << s << endl << l << endl << h << endl;
  
  return 0;
}

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

using namespace std;

int main () {
	int n, e;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int mx = a[n - 1];
	float rv = mx / 2.0;
	auto itu = upper_bound(a.begin(), a.end(), mx / 2);
	auto itl = prev(itu);
	int mn = (abs(rv - *itu) >= abs(*itl - rv)) ? *itl : *itu;
	cout << mx << " " << mn;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
#define Max (int)450
#define MAX2 (int)1e5+5
#define MOD ((int)1e9+7)
using namespace std;



int main(){
	char s[4];
	int i;
	
	scanf("%s",s);
	int f = 0;
	for(i=0;i<3;i++){
		if(s[i] == s[i+1]){
			f = 1;
			break;
		}
	}
	if(f)
		printf("Bad\n");
	else
		printf("Good\n");
	return 0;
}



Measured memory_bytes: 256
(function() {
    'use strict';

    var lines = [];
    require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    }).on('line', function(line) {
      lines.push(line);
    });
    process.stdin.on('end', function() {
      //lines.forEach(function(line) {
        //var tokens = line.split(' ').map(Number);
        //    console.log(tokens[0] + ' ' + tokens[1]);
      //}
      //)
      ;

    // ToDo start
      var N = parseInt(lines[0])
      var ans = 0

      var sqrtN = Math.floor(Math.sqrt(N))
      var ans = sqrtN * sqrtN

      for (var i=sqrtN;i*i<=N;i++){
        var test = i*i
        if(test <= N){
            ans = test
        }
      }

    console.log(ans)
      
//      console.log( Math.pow(parseInt(lines[0]),2) - parseInt(lines[1])  )
    // ToDo end

    });


})();



Measured memory_bytes: 7628
def m(n)
  n == 0 ? 1 : m(n-1)*2+3
end

def b(n)
  n == 0 ? 1 : b(n-1)*2+1
end

def f(n,x)
  return 0 if x<1
  return 1 if n==0
  t = m(n)
  x > t/2 ? f(n-1,x-t/2-1)+b(n-1)+1 : f(n-1,x-1)
end

n,x=gets.split.map &:to_i
p f(n,x)

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INFLL=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void solve(){
    int n;
    cin >> n;
    
    vector<int> dp(n,INF);
    rep(i,0,n){
        int a;
        cin >> a;
        *(lower_bound(dp.begin(),dp.end(),a))=a;
    }
    
    for(int i=n-1; i>=0; --i) if(dp[i]!=INF){
        cout << i+1 << endl;
        break;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 1528
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    mytype x=n/1.08;
    m=ceil(x);

    if(m*108/100==n)
        cout<<m<<endl;
    else
        cout<<":("<<endl;

}   aryanc403();
    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());

            var remin = X - A;
            Console.WriteLine(remin%B);
        }
    }
}


Measured memory_bytes: 13140