akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// https://atcoder.jp/contests/abc106/tasks/abc106_b

// 約数列挙
vector<int> divisor_list(int n){
    vector<int> ans;
    // 約数のペアの小さい方はi^2までにある
    for(int i=1; i*i<=n; i++){
        if(n%i==0){
            int tmp = n/i;
            ans.push_back(tmp);
            ans.push_back(i);
        }
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i=i+2){
        vector<int> li = divisor_list(i);
        if (li.size()==8) ans++;
    }

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
//sort(a, a + N, greater<ll>())   // descend
//sort(a, a+N)                    //  ascend

/* 
void comb(vector<vector <ll> > &v) {
	ll mod=1000000007;
	rep (i,0,v.size()) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	rep (k,1,v.size()) {
		rep (j,1,k) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
		}
	}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

int main(){
	ll n;
	cin>>n;
	ll h[30];
	rep(i,0,n) cin>>h[i];
	ll cnt=1;
	ll m=h[0];
	rep(i,1,n) {
		if(h[i]>=m) cnt++;
		m=max(m,h[i]);
	}
	cout<<cnt;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
if a>b:
    print(0)
elif n==1 and a!=b:
    print(0)
elif n==1:
    print(1)
elif n==2:
    print(1)
else:
    if a==b:
        print(1)
    else:
        n-=2
        print((b-a)*n+1)


Measured memory_bytes: 2940
import java.util.*;
    
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S;
    int count = 0;
    S = sc.next();
    for(int i = 0; i < 3; i++){
      if(S.charAt(i)=='o'){
        count++;
      }
    }
    System.out.println(700+count*100);
  }
}

Measured memory_bytes: 21716
x0,y0,r0,x1,y1,r1=$<.read.split.map(&:to_i)
d=Math.hypot(x0-x1,y0-y1)
r0,r1=[r0,r1].minmax
if d>r0+r1
	p 4
elsif d==r0+r1
	p 3
elsif d>r1-r0
	p 2
elsif d==r1-r0
	p 1
else
	p 0
end

Measured memory_bytes: 8748
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli unsigned long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)

#define TATE 0
#define YOKO 1

int main(){

	lli h,w,n;
	cin>>h>>w>>n;

	vector<lli> a(n);
	REP(i,n)cin>>a[i];

	/* 一筆書きをおこなう */
	lli data[h][w];
	lli now = 0;
	lli cnt = 0;
	for(lli i=0;i<h;i++){
		if(DEBUG)cout<<"i="<<i<<endl;
		lli j;
		if(i%2==0)j=0;
		else j = w-1;

		while(0<=j && j<w){
			if(DEBUG)cout<<"j="<<j<<endl;
			if(cnt >= a[now]){
				now++;
				cnt=0;
			}
			
			data[i][j] = now+1;
			cnt++;

			if(i%2==0) j++;
			else j--;
		}
	}

	REP(i,h){
		REP(j,w)cout<<data[i][j]<<" ";
		cout<<endl;
	}


	return 0;
}
 

Measured memory_bytes: 384
import math
from functools import reduce
from collections import deque, defaultdict
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        s = input()
        d[s] += 1

    print("AC x {}".format(d["AC"]))
    print("WA x {}".format(d["WA"]))
    print("TLE x {}".format(d["TLE"]))
    print("RE x {}".format(d["RE"]))

main()

Measured memory_bytes: 68904
#include <iostream>
using namespace std;
int main(void){
    
    int a, b;
    
    cin >> a >> b;
    
    if (a < b){
        cout <<"a < b"<< endl;
    }
    
    else if (a > b){
        cout <<"a > b"<< endl;
    }
    
    else {
        cout <<"a == b"<< endl;
    }
}


Measured memory_bytes: 3096
#include<stdio.h>
int main()
{
	int k,i,x,s;
	while(scanf("%d",&k),k)
	{
		for(s=i=0;i<k*(k-1)/2;++i)scanf("%d",&x),s+=x;
		printf("%d\n",s/(k-1));
	}
	return 0;
}

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

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    int a[100];
    while(cin>>n && n){
        rep(i,n)cin>>a[i];
        int ans=1<<20;
        rep(i,1<<n){
            int d=0;
            rep(j,n)if(i>>j&1)d+=a[j];else d-=a[j];
            ans=min<int>(ans,abs(d));
        }
        cout<<abs(ans)<<endl;
    }
}

Measured memory_bytes: 1160
package main

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

func parseInt(s string) (n int) {
	n, _ = strconv.Atoi(s)
	return
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	n := make([]int, 4)

	for i := range n {
		s.Scan()
		n[i] = parseInt(s.Text())
	}
	a := n[1] - (n[1] / n[2]) - (n[1] / n[3])
	b := n[0] - ((n[0] - 1) / n[2]) - ((n[0] - 1) / n[3])
	c := (n[1] / lcm(n[2], n[3]))
	d := ((n[0] - 1) / lcm(n[2], n[3]))
	ans := a - b + (c - d) + 1

	fmt.Println(ans)
}


Measured memory_bytes: 640
function main(input) {
  const [[N, D], ...pList] = input.split('\n').map(str => str.split(' ').map(Number))
  let count = 0;
  pList.forEach(val => {
    const [x, y] = val;
    Math.sqrt(x * x + y * y) <= D && count++;
  })
  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 97564
n = int(input())
a = list(map(int, input().split()))

buy = [0] # 買う日
sell = [] # 売る日

target = 0
i = 1
while i < n:
    if a[i] >= a[i-1]:
        # 売らなくていい
        if i == n-1:
            # 最終日なので売る
            sell.append(i)
    else:
        # 売るべき
        sell.append(i-1)
        buy.append(i)
    i += 1
# print(buy, sell)

money = 1000 # 現金
stock = 0 # 株
for i in range(n):
    # print(money, stock)
    if i in buy and i != n-1:
        if not i in sell:
            stock += money // a[i]
            money = money % a[i]
    elif i in sell:
        if not i in buy:
            money += stock*a[i]
            stock = 0
print(money)


Measured memory_bytes: 9220
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int m, d;
    cin >> m >> d;

    int ans = 0;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= d; j++)
            if (j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i)
                ans++;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n][2];
    REP(i,n){
        cin>>arr[i][0]>>arr[i][1];
    }
    ll flag=0;
    ll cnt=0;
    for(ll i=0;i<n;i++){
        if(arr[i][0]==arr[i][1]){
            cnt++;
        }
        else{
            cnt=0;
        }
        if(cnt==3){
            flag=1;
            break;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
    cin>>a>>b;
    if(a%3==0)
    {
    	cout<<"Possible";
		return 0; 
	}
	else
	{
		if(b%3==0)
		{
			cout<<"Possible";
			return 0;
		}
		else
		{
			if((a+b)%3==0)
			{
				cout<<"Possible";
				return 0;
			}
			else
			{
				cout<<"Impossible"; 
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
s = input()
count = 0
maxcount = 0

for i in range(len(s)):
    check = s[i:i+1]
    if check == "A" or check == "C" or check == "G" or check == "T":
        count += 1
    else:
        maxcount = max(maxcount, count)
        count = 0

maxcount = max(maxcount, count)
print(maxcount)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>

int main(){
    unsigned int N;
    int L;
    std::cin >> N;
    std::cin >> L;

    int taste_1=0;
    int taste_2=0;
    for (int i=1; i<N+1;i++){
        taste_1+= L + i -1;
    }

    int taste_rank1=0;
    for (int i=1; i<N+1;i++){
        for(int j=1; j<N+1; j++){
            if (i==j) continue;
            taste_2+= L + j -  1;
        }
        if (std::abs(taste_1 - taste_rank1) > std::abs(taste_1 - taste_2)){
            taste_rank1 = taste_2;
        }
        taste_2=0;
    }
    std::cout << taste_rank1;

}

Measured memory_bytes: 256
integer N
logical,allocatable,dimension(:,:)::Black
character(500) S
logical Bexist

integer Gyo,Retsu
integer C
logical FLAW

integer x,prex
read*,N
allocate(Black(N,N))
Black=.false.
Bexist=.false.
do i=1,N
  read*,S
  do j=1,N
    if(S(j:j)=="#")then
      Black(i,j)=.TRUE.
      Bexist=.TRUE.
    endif
  end do
end do

if(.not.Bexist)then
  print"(i0)",-1
  stop
endif

C=0
do Retsu=1,N
  FLAW=.FALSE.
  do j=1,N
    FLAW=FLAW.or.(.not.Black(j,Retsu))
  end do
  if(FLAW)C=C+1
end do

x=huge(x)
do Gyo=1,N
  Bexist=.FALSE.
  do i=1,N
    if(Black(i,Gyo))Bexist=.TRUE.
  end do
  prex=0
  do i=1,N
    if(.not.Black(Gyo,i))prex=prex+1
  end do
  if(.not.Bexist)prex=prex+1

  x=min(x,prex)
end do

print"(i0)",x+c

end

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define MP std::make_pair
#define PB push_back
#define FI first
#define SE second
#define M 1000005
typedef long long ll;
ll n,X[M],Y[M],S[M],flag;
ll read(){
	char c=getchar();ll ans=0;bool flag=1;
	while (c<'0'||c>'9') flag&=(c!='-'),c=getchar();
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	return flag?ans:-ans;
}
void Write(ll x){
	if (x<10) putchar(x^48);
	else Write(x/10),putchar((x%10)^48);
	return;
}
ll abs(ll x){return x>0?x:-x;}
bool check(ll x,ll y,ll d){
	return abs(x)+abs(y)<(1<<d+1);
}
void solve(ll x,ll y,ll d){
	if (d<0) return assert(!x&&!y),void();
	if (check(x+(1<<d),y,d-1)) return printf("L"),solve(x+(1<<d),y,d-1);
	if (check(x-(1<<d),y,d-1)) return printf("R"),solve(x-(1<<d),y,d-1);
	if (check(x,y+(1<<d),d-1)) return printf("D"),solve(x,y+(1<<d),d-1);
	if (check(x,y-(1<<d),d-1)) return printf("U"),solve(x,y-(1<<d),d-1);
	return assert(0),void();
}
int main(){
	n=read();
	for (ll i=1;i<=n;i++) X[i]=read(),Y[i]=read();
	for (ll i=2;i<=n;i++)
		if ((X[i]+Y[i]-X[1]-Y[1])&1) return !printf("-1");
	if ((X[1]+Y[1]+1)&1) S[++*S]=1;
	for (ll i=30;i>=0;i--) S[++*S]=1<<i;
	printf("%d\n",*S);
	for (ll i=1;i<=*S;i++) printf("%d ",S[i]);printf("\n");
	for (ll i=1;i<=n;i++){
		if ((X[i]+Y[i]+1)&1) printf("R"),X[i]--;
		solve(X[i],Y[i],30),printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
typedef long long ll;

using namespace std;

struct xyz {
    int a;
    int b;
};

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<xyz> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i].a >> v[i].b;
    }
    
    sort(v.begin(), v.end(), [](const xyz &x, const xyz & y){return x.a < y.a;});
    
    priority_queue<int> que;
    int add_index = 0;
    ll ans = 0;
    for(int i = 1; i <= m; i++) {
        while(add_index < n && v[add_index].a <= i) {
            que.push(v[add_index].b);
            add_index++;
        }
        
        if(!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1660
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int a = scan.nextInt();
	    int b = scan.nextInt();
	    int c = scan.nextInt();
	    int x = scan.nextInt();
	    scan.close();
	    int cnt=0;
	    for(int i=0;i<=a;i++) {
	    	for(int j=0;j<=b;j++) {
	    		for(int k=0;k<=c;k++) {
			    	if(x==500*i+100*j+50*k) {
			    		cnt++;
			    	}
	    		}
		    }
	    }
	    System.out.println(cnt);
	}

}

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

#define ll long long

int h,w,k;
int hw[301][301];
string s[301];
bool ecake[301];
bool onecake[301];

void solve(){
    cin>>h>>w>>k;
    int cnt=1;
    for(int i=0; i<h; i++){
        cin>>s[i];
    }
    for(int i=0; i<h; i++){
        int ccnt=0;
        ecake[i]=false;
        onecake[i]=false;
        for(int j=0; j<w; j++){
            if(s[i][j]=='#')ccnt++;
        }
        if(ccnt==0){
            ecake[i]=false;
        }
        else if(ccnt==1){
            onecake[i]=true;
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(onecake[i]){
                //cout<<"hatudou "<<i<<endl;
                for(int k=0; k<w; k++){
                    hw[i][k]=cnt;
                }
                cnt++;
                break;
            }
            if(s[i][j]=='#'){
                //if(i==0 && j==2)cout<<"hello "<<cnt<<endl;
                hw[i][j]=cnt;
                for(int k=1; j+k<w; k++){
                    if(s[i][j+k]=='#'){
                        j+=k-1;
                        break;
                    }
                    hw[i][j+k]=cnt;
                }
                cnt++;
            }
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(hw[i][j]==0){
                for(int k=1; k+j<w; k++){
                    if(hw[i][j+k]!=0){
                        hw[i][j]=hw[i][j+k];
                        break;
                    }
                }
            }
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(hw[i][j]==0){
                for(int k=1; k+i<h; k++){
                    if(hw[k+i][j]!=0){
                        hw[i][j]=hw[k+i][j];
                        break;
                    }
                }
            }
            if(hw[i][j]==0){
                for(int k=-1; k+i>=0; k--){
                    if(hw[k+i][j]!=0){
                        hw[i][j]=hw[k+i][j];
                        break;
                    }
                }
            }
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w-1; j++){
            cout<<hw[i][j]<<" ";
        }
        cout<<hw[i][w-1]<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

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

namespace CSharpSample01
{


    class Program
    {

        static double Solve(int n, int[] a)
        {
            a = a.OrderBy(x => x).ToArray();

            double rec = a[0];

            for (int i = 1; i < n; i++)
            {
                rec = (rec + a[i]) / 2;
            }

            return rec;
        }
        

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Console.WriteLine(Solve(n, a));
        }
    }
}

Measured memory_bytes: 13396
void main()
{
    long[] tmp = rdRow;
    long h = tmp[0], w = tmp[1];
    string[] s = h.rdCol!string;

    long[] dy = [-1, 0, 1, 0], dx = [0, 1, 0, -1];
    long[][] dist = new long[][](h, w);
    long result;
    foreach (i; 0 .. h)
    {
        foreach (j; 0 .. w)
        {
            if (s[i][j] == '#') continue;
            foreach (k; 0 .. h)
            {
                dist[k][] = -1;
            }
            dist[i][j] = 0;
            coord[] que;
            que ~= coord(i, j);
            long len;
            while (!que.empty)
            {
                long y = que[0].y, x = que[0].x;
                que.popFront;
                foreach (dir; 0 .. 4)
                {
                    long y1 = y + dy[dir], x1 = x + dx[dir];
                    if (y1 < 0 || h <= y1 || x1 < 0 || w <= x1) continue;
                    if (s[y1][x1] == '#') continue;

                    if (dist[y1][x1] == -1) {
                        que ~= coord(y1, x1);
                        dist[y1][x1] = dist[y][x] + 1;
                        len = max(len, dist[y1][x1]);
                    }
                }
            }
            result = max(result, len);
        }
    }
    result.writeln;
}

alias Tuple!(long, "y", long, "x") coord;

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int main( )
{
	long long a,b;
	cin>>a>>b;
	if(a==1||b==1)
	{
		cout<<1;
		return 0;
	}
	if(a*b%2!=0)
	{
		cout<<a*b/2+1;
		return 0;
	}
	
	cout<<a*b/2;	
	
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int L;
  int R;
  int d;
  int i;
  int t=0;
  scanf("%d%d%d",&L,&R,&d);
  for(i=1;i<=R;i++)
  {
    if(i*d>=L&&i*d<=R)
		t++;
	if(i*d>R)
		break;
  }
  printf("%d",t);
}


Measured memory_bytes: 1684
// youngjinp20
// 2020 03

#include <bits/stdc++.h>
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
using namespace std;

typedef long long ll;

const int MAX = 3000 + 1;
char a[MAX], b[MAX];
char hist[MAX][MAX];
pair<int, int> pre[MAX][MAX];
int dp[MAX][MAX];

int main() {
	cin >> a >> b;
	int len1 = strlen(a);
	int len2 = strlen(b);

	for (int i=1; i<=len1; i++) {
		for (int j=1; j<=len2; j++) {
			if (smax(dp[i][j], dp[i-1][j])) {
				pre[i][j] = {i-1, j};
			}
			if (smax(dp[i][j], dp[i][j-1])) {
				pre[i][j] = {i, j-1};
			}
			if (a[i-1] == b[j-1] && smax(dp[i][j], dp[i-1][j-1] + 1)) {
				hist[i][j] = a[i-1];
				pre[i][j] = {i-1, j-1};
			}
		}
	}

	stack<char> S;
	pair<int,int> c = {len1, len2};

	while (c.first != 0 && c.second != 0) {
		if (hist[c.first][c.second]) S.push(hist[c.first][c.second]);
		c = pre[c.first][c.second];
	}

	while(!S.empty()) {
		cout << S.top();
		S.pop();
	}

	return 0;
}


Measured memory_bytes: 114560
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
p=n1()
ans=0
for i in range(1,n-1):
    if p[i-1]<p[i]<p[i+1] or p[i-1]>p[i]>p[i+1]:
        ans+=1
print(ans)

Measured memory_bytes: 3444
#include <stdio.h>

int F(int A, int B){
  if(B % A != 0) return B - A;
  else return A + B;
} 

int main(void){
  int A, B;
  scanf("%d %d", &A, &B);
  printf("%d\n", F(A, B));
  return 0;
}


Measured memory_bytes: 128
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) {
    list($x[$i], $y[$i]) = ints();
    $v[$x[$i]][$y[$i]] = true;
}
$max = 0;
for ($i = 0; $i < $n - 1; ++$i) {
    for ($j = $i + 1; $j < $n; ++$j) {
        $dx = $x[$j] - $x[$i];
        $dy = $y[$j] - $y[$i];
        if (isset($cnt[$dx][$dy])) $cnt[$dx][$dy]++;
        else $cnt[$dx][$dy] = 1;
        if (isset($cnt[-$dx][-$dy])) $cnt[-$dx][-$dy]++;
        else $cnt[-$dx][-$dy] = 1;
    }
}
$max = 0;
foreach ($cnt as $i => $v) $max = max($max, max($v));
echo $n - $max;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	VI a(n);
	for(auto& ia: a) cin >>ia;
	
	map<int, int> mpi, mpj;
	rep(i, n){
		mpi[a[i] + i]++;
		mpj[i - a[i]]++;
	}
	ll ans = 0;
	for(auto& x: mpi) if(mpj.count(x.first)){
		ans += (ll)x.second * mpj[x.first];
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 21312
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int segtree[262144];
void update(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c)return ;
	if(c<=a&&b<=d){
		segtree[e]=max(segtree[e],f);
		return;
	}
	update(a,(a+b)/2,c,d,e*2,f);
	update((a+b)/2+1,b,c,d,e*2+1,f);
}
int query(int a){
	a+=131072;
	int ret=0;
	while(a){
		ret=max(ret,segtree[a]);
		a/=2;
	}
	return ret;
}
vector<int> g[100000];
int L[100000];
int R[100000];
int Z[100000];
int val;
void dfs(int a){
	L[a]=val++;
	for(int i=0;i<g[a].size();i++)
		dfs(g[a][i]);
	R[a]=val-1;
}
char str[2];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		val=0;
		for(int i=0;i<262144;i++)segtree[i]=0;
		for(int i=0;i<a;i++)g[i].clear();
		for(int i=1;i<a;i++){
			int c;
			scanf("%d",&c);
			c--;
			g[c].push_back(i);
		}
		dfs(0);
		for(int i=0;i<a;i++)Z[L[i]]=i;
		long long ret=0LL;
		for(int i=0;i<b;i++){
			int d;
			scanf("%s%d",str,&d);
			d--;
			if(str[0]=='M'){
				update(0,131071,L[d],R[d],1,L[d]);
			}else{
				ret+=Z[query(L[d])]+1;
				//printf("%d\n",query(L[d]));
			}
		}
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 12404
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;

	writeln(max(A+B, max(A - B, A * B)));
	stdout.flush();
	debug readln();
}

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

int digit(int x) {
	int ret = 0;
	while (x > 0) {
		ret += x % 10;
		x /= 10;
	}
	return ret;
}

int main() {
	int n;
	cin >> n;
	if (n % digit(n) == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	char topping[3];
	int sum = 700;
	int i;

	scanf("%s", topping);

	for(i = 0; i < 3; i++){
		if(topping[i] == 'o'){
			sum += 100;
		}
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static final int MAX = 200;

	public static final int INF = Integer.MAX_VALUE / 2 - 1;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		Map<String, Integer> dict = new HashMap<String, Integer>();
		
		int[] from = new int[MAX];
		int[] to   = new int[MAX];
		int[] dist = new int[MAX];
		int[][] adj = new int[MAX][MAX];
		
		while (true) {
			final int n = sc.nextInt();

			if(n == 0){
				break;
			}
			
			dict.clear();
			
			int count = 0;
			for(int i = 0; i < n; i++){
				sc.nextInt(); //1
				
				//A
				String from_str = sc.next();
				if(!dict.containsKey(from_str)){
					dict.put(from_str, count);
					count++;
				}
				from[i] = dict.get(from_str);
				
				sc.next(); //=
				
				//^~
				dist[i]= Integer.parseInt(sc.next().split("\\^")[1]);
				
				//B
				String to_str = sc.next();
				if(!dict.containsKey(to_str)){
					dict.put(to_str, count);
					count++;
				}
				to[i] = dict.get(to_str);
			}
			
			for(int i = 0; i < count; i++){
				for(int j = 0; j < count; j++){
					adj[i][j] = i == j ? 0 : INF;
				}
			}
			
			for(int i = 0; i < n; i++){
				adj[from[i]][to[i]] =  dist[i];
				adj[to[i]][from[i]] = -dist[i];
			}
			
			for(int k = 0; k < count; k++){
				for(int i = 0; i < count; i++){
					for(int j = 0; j < count; j++){
						adj[i][j] = Math.min(adj[i][j], adj[i][k] + adj[k][j]);
					}
				}
			}
			/*
			for(int i = 0; i < count; i++){
				for(int j = 0; j < count; j++){
					System.out.print(adj[i][j] + " ");
				}
				System.out.println();
			}
			*/
			boolean flag = false;
			for(int i = 0; i < count; i++){
				if(adj[i][i] != 0){
					flag = true;
					break;
				}
			}
			
			System.out.println(flag ? "No" : "Yes");
		}

	}

}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;

void Main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;

  vll r, g, b;

  REP(i, s.length()) {
    if (s[i] == 'R') {
      r.pb(i);
    }
    else if (s[i] == 'G') {
      g.pb(i);
    }
    else {
      b.pb(i);
    }
  }

  ll count = r.size() * g.size() * b.size();
  REP(i, n) {
    FOR(j, i + 1, n - 1) {
      ll k = 2 * j - i;
      if (k < n) {
        if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k]) {
          count--;
        }
      }
    }
  }
  COUT(count);
}

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

/*

3 2
*/


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define foi(i,k,n) for (int i = (int)k; i < (int)n; ++i)

using namespace std;
using ll = long long;
using ii = pair<int,int>;

constexpr int MOD = 7 + 1000000000;
constexpr int MAXN = 5 + 100000;

int mul(int a, int b) {
  return (int)((1LL*a*b)%MOD);
}

int add(int a, int b){
  int ans = a + b;
  if (ans >= MOD) ans -= MOD;
  return ans;
}

int sub(int a, int b) {
  int ans = a - b;
  if (ans < 0) ans += MOD;
  return ans;
}

int fpow(int b, int e) {
  int ans = 1, p = b;
  for (; e; e >>= 1) {
    if(e & 1) ans = mul(ans, p);
    p = mul(p, p);
  }
  return ans;
}

int memo[MAXN];
int f(int n, int k) {
  int& ans = memo[k];
  if (ans != -1) return ans;
  ans = fpow(k,n);
  int l = k;
  while (true) {
    if (l < 2) break;
    int low = 2, high = l, best = -1;
    while (low <= high) {
      int mid = (low + high) >> 1;
      if (k/mid == k/l) {
        high = mid - 1;
        best = mid;
      } else {
        low = 1 + mid;
      }
    }
    ans = sub(ans, mul(f(n, k/l), 1+l-best));
    l = best - 1;
  }
  return ans;
}


int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int n,k,ans=0; cin >> n >> k;
  memset(memo, -1, sizeof memo);
  for (int i = 1; i <= k; ++i) ans = add(ans, mul(i, f(n,k/i)));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4024
n = int(input())
l = list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
  if i==1:
    dp[i]=abs(l[i]-l[i-1])
  else:
    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
print(dp[n-1])

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;
typedef unsigned int i64;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back

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

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


template <typename T>
void printV(vector<T> A) {
  if (A.empty()) cerr << "EMTPY\n";
  else { 
    cerr << "[";
    for (int i = 0; i < A.size() -1 ; ++i) {
      cerr << A[i] << ", ";
    }
    if (A.size()) cerr << A.back() << "]\n";
  }
}


template <typename T>
void printVV(vector<vector<T>> A) {
  cerr << "[";
  for (auto v : A) {
    printV<T>(v);
  }
  cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  ll ret = 1;
  bool overflow = false;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(),a.end(),greater<ll>());
  if (a.back() == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    ll nret = ret * a[i];
    if (nret > 1000000000000000000 || nret < ret) overflow = true;
    ret = nret;
  }
  if (overflow) cout << -1 << endl;
  else cout << ret << endl;
  return 0;
}



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

typedef long long ll;
typedef vector <ll> vr;
typedef pair <ll, ll> pr;
typedef vector <ll> :: iterator ir;

#define pub push_back
#define pob pop_back
#define mp make_pair
#define pc __builtin_popcount
#define lb lower_bound

ll dig(ll n) {
	string s = to_string(n);
	return s.size();
}

ll totSum(ll arr[], ll n) {
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		sum += arr[i];
	}
	return sum;
}


int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);





// write your code here

	string s, t;
	cin >> s >> t;
	ll ans = INT_MAX;
	for (size_t i = 0; i < s.length() - t.length() + 1 ; i++) {
		ll tmp = i;
		ll count = 0;
		for (size_t j = 0; j < t.length(); j++) {
			if (s[tmp] != t[j])count++;
			tmp++;
		}
		ans = min(count, ans);
	}
	cout << ans;

// this is the end of your code

}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N, K;
int ans;

int main(){
	cin >> N >> K;
	while (N > 0){
		N /= K;
		ans++;
	}
	
	cout << ans << endl;

	return 0;
}

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;
  string S;
  cin >> N >> S;
  string ans = S;
  string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  rep(i, S.size()) {
    rep(j, alpha.size()) {
      if (S.at(i) == alpha.at(j)) {
        if (j + N > alpha.size() - 1)
        {
          ans.at(i) = alpha.at(j + N - 26);
        }
        else
        {
          ans.at(i) = alpha.at(j + N);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 101;
char g[maxn][maxn];
bool vis[maxn][maxn];
string s;
int cnt;
int n , m;
char ch;
int d[4][2] = { -1 , 0 , 0 , 1 , 1 , 0 , 0 , -1 };
void dfs(int x , int y)
{
    vis[x][y] = false;
    for(int i = 0 ; i < 4 ; i ++)
    {
        int xx = x + d[i][0];
        int yy = y + d[i][1];
        if(xx >= 0 && xx < n && yy >= 0 && yy < m && vis[xx][yy] && g[xx][yy] == g[x][y])
            dfs(xx , yy);
    }
}

int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    while(cin >> n >> m)
    {
        if(n == 0 && m == 0)
            break;
        for(int i = 0 ; i < n ; i ++)
        {
            cin >> s;
            for(int j = 0 ; j < m ; j ++)
            {
                g[i][j] = s[j];
            }
        }
        cnt = 0;
        memset(vis , true , sizeof(vis));
        for(int i = 0 ; i < n ; i ++)
        {
            for(int j = 0 ; j < m ; j ++)
            {
                if(vis[i][j])
                {
                    dfs(i , j);
                    cnt ++;
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if(abs(A - B) > 1e18) cout << "Unfair" << endl;
  else{
    if(K % 2 == 0) cout << A - B;
    else cout << B - A;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
	int a,b,index=1,i=0,j=0,f[100],g[100];
	while((scanf("%d",&a))!=EOF)
	{
		scanf("%d",&b);
		if(a<0||a>1000000||b<0||b>1000000)
		{
			break;
		 } 
		f[i]=a+b;
		while(f[i]>=10)
		{
			f[i]/=10;
			index++;
		}
		g[i]=index;
		index=1;
		i++;
		if(i>200)
		break;
	}
	while(j<i)
	{
		printf("%d\n",g[j]);
		j++;
	}
	return 0;
}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
typedef pair<LL,LL> PII;
const int N=200010;
int read(){
	char c=getchar();int d=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';d=d*10+c-48,c=getchar());
	return d*f;
}
int n,t[N],tt[N];LL w[N];PII a[N];
void upd(pair<int,PII>&ans,int a,LL b,LL c){
	if(ans.fi<a)ans=mp(a,mp(b,c));else
	if(ans.fi==a && b*ans.se.se>ans.se.fi*c)ans=mp(a,mp(b,c));
}
LL A[N];int B[N];pair<int,PII> ans=mp(0,mp(0,1));
bool cmp(int x,int y){return a[x].se<a[y].se;}
void add(int x,LL a,int b){for(;x<=n;x+=x&-x)A[x]+=a,B[x]+=b;}
int main(){
	n=read();
	ref(i,1,n)a[i].se=read(),a[i].fi=read();
	sort(a+1,a+n+1);
	ref(i,1,n)w[i]=max(0LL,a[i].fi-a[i].se);
	ref(i,1,n)t[i]=i;
	sort(t+1,t+n+1,cmp);
	ref(i,1,n)tt[t[i]]=i;
	def(i,n,1)w[i]+=w[i+1];
	ref(i,1,n)add(i,a[t[i]].se,1);
	def(i,n,1){
		add(tt[i],-a[i].se,-1);
		LL nw=w[i+1]+a[i].fi-a[i].se;
		if(nw>0){
			int m=4;
			int pos=0;
			LL sa=0;int sb=0;
			def(j,16,0)if(pos+(1<<j)<=n)
				if(sa+A[pos+(1<<j)]<=nw){pos+=(1<<j);sa+=A[pos];sb+=B[pos];}
			if(sa+A[pos+1]<=nw){pos++;sa+=A[pos];sb+=B[pos];}
			upd(ans,sb,min(nw-sa,a[i].fi),a[i].fi);
		}
	}
	LL x1=ans.fi*ans.se.se+ans.se.fi,x2=ans.se.se*n;
	LL g=__gcd(x1,x2);x1/=g;x2/=g;
	cout<<x1<<" "<<x2<<endl;
}

Measured memory_bytes: 7552
h, w = map(int, input().split())
grid = []
for _ in range(h):
    grid.append(input())

dp = [0]*(w+1)
dp[1] = 1
for i in grid:
    newdp = dp[:]
    for j, k in enumerate(i):
        newdp[j+1] = dp[j+1] + newdp[j] if k=='.' else 0
    dp = newdp
print(dp[-1]%(10**9+7))

Measured memory_bytes: 53596
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ll MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N;
    cin>>N;
    
    VEC(ll,a,N+1);
    REP1(i,N){
        cin>>a[i];
    }
    
    ll t=1;
    REP1(i,100000){
        t=a[t];
        if(t==2){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int r;
	cin>>r;
	ld Radius = r;
	ld pi = 3.14159265359;
	cout<<fixed<<setprecision(8)<<2*pi*Radius<<"\n";
	return 0;
}

Measured memory_bytes: 3804
/*****************************************************

Code by: Vichitr
Compiled On: 23rd March 2019

*****************************************************/

#include<bits/stdc++.h>
#define MAX 9223372036854775807
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
#define pf pop_front
#define mp make_pair
#define loop(i,n) for(int i=0;i<n;i++)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ip pair<int, int>
#define N 100007
const ll MOD = 1e9+7;
const ll SZ = 107;


signed main()
{
    fast;

    int n, k;
    cin>>n>>k;
    int h[n+5];
    for(int i=1;i<=n;i++) cin>>h[i];
    int dp[n+5];
    dp[0]=dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
        for(int j=2;j<=k;j++)
            if(i-j>=1)
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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


int main(int argc, char const *argv[]) {
    int n;
    cin>>n;
    bool ok = false;

    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (i*j==n) ok = true;
        }
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/* ITP1_8_C */
import java.io.*;

class Main
{
  static final int ALPHABET = 26;

  public static void main(String[] args)
  {
    int[] count = new int[ALPHABET];
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String str = "";

      while((str = br.readLine()) != null){
        str = str.toLowerCase();

        for(char c : str.toCharArray()){
          if(Character.isLetter(c))
            count[c - 'a']++;
        }
      }

      for(int i = 0; i < count.length; i++){
        System.out.println((char)('a' + i) + " : " + count[i]);
      }
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24100
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define s(x) (x).begin(),(x).end();
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
int main(){
  string num;
  cin>>num;
  int how= num.length();
  ll ans =0;
  rep(i,1<<(how-1)){
    ll sm =0;
    ll a = num[0]-'0';
    rep(j,how-1){
      if(i&(1<<j)){
        sm+=a;
        a=0;
      }
      a=a*10+num[j+1]-'0';
    }
    sm += a;
    ans+=sm;
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 2e5 + 9, M = 3e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

vector<int> vec[N];
int turnon[11], state[11], freq[11];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  int n, m, k, a;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> a;
      --a;
      vec[i].push_back(a);
    }
  }
  for (int i = 0; i < m; ++i)
    cin >> state[i];
  ll ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    memset(freq, 0, sizeof freq);
    memset(turnon, 0, sizeof turnon);
    for (int j = 0; j < n; ++j) {
      if((i) & (1 << j)) {
        turnon[j] = 1;
      }
    }
    int cnt = 0;
    for (int ff = 0; ff < m; ++ff) {
      int noww = 0;
      for(auto it: vec[ff]) {
        noww += turnon[it];
      }
      if(noww % 2 == state[ff] % 2)
        ++cnt;
    }
    if(cnt == m) {
      ++ans;
//      cout << i << endl;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 4992