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

const int MAX = 100000;

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs(int current, int prev)
{
	//访问结点current之后立即进行的处理
	prenum[current] = lowest[current] = timer;
	++timer;
	visited[current] = true;
	int next;
	for (int i = 0; i < G[current].size(); ++i)
	{
		next = G[current][i];
		if (!visited[next]){
			parent[next] = current;
			dfs(next, current);
			lowest[current] = min(lowest[current], lowest[next]);
		}else if (next != prev){
			lowest[current] = min(lowest[current], prenum[next]);
		}
	}
	//结点current搜索完毕之后立即进行的处理
}

void art_points(){
	for (int i = 0; i < N; ++i)visited[i] = false;
	timer = 1;
	//计算lowest
	dfs(0, -1);
	set<int> ap;
	int np = 0;
	for (int i = 1; i < N; ++i){
		int p = parent[i];
		if (p == 0)++np;
		else if (prenum[p] <= lowest[i])ap.insert(p);
	}
	if (np > 1)ap.insert(0);
	for (auto it(ap.begin()); it != ap.end(); ++it)cout << *it << endl;
}

int main()
{
	int m;
	cin >> N >> m;
	for (int i = 0; i < m; ++i)
	{
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	art_points();
	return 0;
}


Measured memory_bytes: 7024
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
typedef __int128 i128;
ll n;
int ds;
ll d[25],np[25];
ll ans;
void div(ll tn){
	for(ll i=2;i*i<=tn;i++){
		if(tn%i) continue;
		d[++ds]=1; np[ds]=i;
		while(tn%i==0) tn/=i,d[ds]*=i;
	}
	if(tn>1) d[++ds]=tn,np[ds]=tn;
}
ll qmult(i128 ta,i128 tb,ll mod){
	return ta*tb%mod; 
}
ll ksm(ll ta,ll tp,ll mod){
	ll s=1;
	for(;tp;ta=qmult(ta,ta,mod),tp>>=1) if(tp&1) s=qmult(ta,s,mod);
	return s;
}
ll calc(ll s1){
	ll s2=2*n/s1,phi,k;
	phi=s2;
//	printf("%lld %lld\n",s1,s2);
	if(s2==1) return s1;
	for(int i=1;i<=ds;i++)
		if(s2%np[i]==0) phi=phi/np[i]*(np[i]-1);
	k=ksm(s1,phi-1,s2);
	k=s2-k;
	return k*s1;
}
void dfs(int i,ll s){
	if(i==ds+1){
		ans=min(ans,calc(s));
		return;
	}
	dfs(i+1,s*d[i]);
	dfs(i+1,s);
}
int main(){
	scanf("%lld",&n);
	div(n*2);
	ans=2*n;
	dfs(1,1);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1832
#include<bits/stdc++.h>
using namespace std;
int a[1010];
int main()
{
	int n, m;
	scanf("%d",&n);
	int i;
	for(i=0; i<n; i++) scanf("%d",&a[i]);
	scanf("%d",&m); 
	while(m--)
	{
		int l, r;
		scanf("%d%d",&l,&r);
		reverse(a+l, a+r);
	}
	for(i=0; i<n; i++) 
	{
		if(i == n-1) printf("%d\n",a[i]);
		else printf("%d ",a[i]);
	}
	return 0;
}


Measured memory_bytes: 3212
N = int(input())
H = list(map(int, input().split()))

ans = 0
count = 0
for i in range(1, N):
    if H[i-1] >= H[i]:
        count += 1
    else:
        ans = max(ans, count)
        count = 0
ans = max(ans, count)
print(ans)

Measured memory_bytes: 85224
#include <cstdio>

int main(){
  int a,b;
  scanf("%d %d", &a, &b );
  bool poss = false;
  if( a % 3 == 0) poss = true;
  if( b % 3 == 0) poss = true;
  if( (a + b) % 3 == 0) poss = true;
  
  if( poss ){
    printf("Possible\n");
  }
  else{
    printf("Impossible\n");
  }
}


Measured memory_bytes: 128
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	AB := strings.Split(sc.Text(), " ")
	A, _ := strconv.Atoi(AB[0])
	B, _ := strconv.Atoi(AB[1])

	add := A + B
	sub := A - B
	mul := A * B

	if add >= sub && add >= mul {
		fmt.Println(add)
	} else if sub >= add && sub >= mul {
		fmt.Println(sub)
	} else if mul >= add && mul >= sub {
		fmt.Println(mul)
	} else {
		fmt.Println("0")
	}
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    i64 la,lb,lc;
    la = 2;
    lb = 1;
    if(n==1){ cout<<1<<endl; return 0; }
    REP(i,n-1){
        lc = la+lb;
        la = lb;
        lb = lc;
    }
    cout<<lc<<endl;
    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
k = []
for i in range(N):
  k.append(input())
a = 0
b = 0 
c = 0
d = 0
for i in k:
  if i =='AC':
    a += 1
  elif i =='WA':
    b += 1
  elif i =='TLE':
    c += 1
  elif i =='RE':
    d += 1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)

Measured memory_bytes: 16320
a = list(input())
b = list(input())
c = list(input())
current = "a"
while True:
    if current == "a":
        if len(a) == 0:
            print("A")
            break
        else:
            current = a.pop(0)
    elif current == "b":
        if len(b) == 0:
            print("B")
            break
        else:
            current = b.pop(0)
    else:
        if len(c) == 0:
            print("C")
            break
        else:
            current = c.pop(0)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
	string s;
	long long k;
	int count = 0;
	cin >> s >> k;
	
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '1') {
			count++;
			continue;
		}
		break;
	}

	if (count >= k) {
		cout << 1 << endl;
	}
	else {
		cout << s[count] << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=2e5+11;
const int M=3e6+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  set<string>s;
  for(int i=1;i<=n;i++){
    string st;
    cin>>st;
    s.insert(st);
  }
  cout<<sz(s);
}


Measured memory_bytes: 19184
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{

	public static void main(String[] args) throws Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int sec = Integer.parseInt(br.readLine());
		int h = sec / 3600;
		int m = (sec % 3600) / 60;
		int s = (sec % 3600) % 60;

		System.out.println(h + ":" + m + ":" + s);

	}
}

Measured memory_bytes: 24176
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
using namespace std;
long long gcd(long long a, long long b)
{
	long long r;
	while (b)
		r = a % b, a = b, b = r;
	return a;
}
bool num(long long a, long long b, long long c,long long d) {
	if (b > a)return false;
	if (b > d)return false;
	if (c >= b)return true;
	long long g = gcd(b, d);
	if (b - g + (a%g)>c) return false;
	else return true;
}
signed main()
{
	ios::sync_with_stdio(false);
	long long t, a, b, c, d;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> a >> b >> c >> d;
		if (num(a, b, c, d))cout << "Yes\n";
		else cout << "No\n";
	}
}

Measured memory_bytes: 256
n = int(input())
P =[]
s = 0
for i in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for j in range(n):s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5)

Measured memory_bytes: 7732
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

using pii = pair<int64_t, int64_t>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
// }}} End

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

    int N, M;
    cin >> N >> M;

    vector<int> a(N), b(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
    }

    vector<int> c(M), d(M);
    for (size_t i = 0; i < M; ++i) {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < N; ++i) {
        pair<int, int> minv = {INF, INF};
        for (int j = 0; j < M; ++j) {
            chmin(minv, make_pair(abs(a[i] - c[j]) + abs(b[i] - d[j]), j + 1));
        }
        cout << minv.second << "\n";
    }

    return 0;
}


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

int main(){
	int kc;
    vector<string> key;
	cin>>kc;
	key.resize(kc);
    for (int i = 0; i < kc; i++) cin>>key[i];
    bool isOpen = false;
    int oc;
	cin>>oc;
    for (int i = 0; i < oc; i++)
	{
        string tkey;
		cin>>tkey;
        bool isOK = false;
        for (vector<string>::iterator ita=key.begin();ita!=key.end();++ita)
		{
			if(*ita==tkey)
			{
				isOK=true;
				break;
			}
		}		
        if (!isOK)
        {
            cout<<"Unknown "<<tkey<<endl;
        }
        else if (isOpen)
        {
            cout<<"Closed by "<<tkey<<endl;
            isOpen = false;
        }
        else
        {
            cout<<"Opened by "<<tkey<<endl;
            isOpen = true;
        }
	}
}

Measured memory_bytes: 1220
object Main extends App {
  import scala.io.StdIn._
  import scala.math
  val str = readLine.trim.toList
  val winCounts = Array.tabulate(26){_ ⇒ 0}
  for (_ ← 0 until str.count{_.isLetter}) {
    val Array(p, c) = readLine.trim.split(' ')
    winCounts(p(0) - 'a') = c.toInt
  }
  Person.winCounts = winCounts
  println(
    str match{
      case winner Winner Nil if winner.isValid && winner.winCount == 0 ⇒ "Yes"
      case _ ⇒ "No"
    }
  )

  sealed trait Winner {
    def isValid: Boolean
    def winCount: Int
  }
  object Winner{
    def unapply(arg: List[Char]): Option[(Winner, List[Char])] = {
      arg match{
        case Person(p)::t ⇒ Some((new Person(p), t))
        case (a, b) Match t ⇒ Some((new Match(a, b), t))
        case _ ⇒ None
      }
    }
  }
  object Person{
    var winCounts: Array[Int] = Array()
    def unapply(str: Char): Option[Int] = {
      str match {
        case c if c.isLetter ⇒ Some(winCounts(c - 'a'))
        case _ ⇒ None
      }
    }
  }
  object Match{
    def unapply(arg: List[Char]): Option[((Winner, Winner), List[Char])] = {
      arg match {
        case '['::(a Winner ('-':: (b Winner ']'::t))) ⇒ Some(((a, b), t))
        case _ ⇒ None
      }
    }
  }
  class Person(override val winCount: Int) extends Winner {
    override def isValid: Boolean = true
  }
  class Match(val left: Winner, val right: Winner) extends Winner {
    override val isValid: Boolean = left.isValid && right.isValid && ((left.winCount > 0 && right.winCount == 0) || (left.winCount == 0 && right.winCount > 0))
    override val winCount: Int = if (left.winCount == 0) right.winCount - 1 else left.winCount - 1
  }
  implicit class ScopeFunc[T](private val value: T) {
    def let[A](func:T ⇒ A): A = func(value)
    def also(func:T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}




Measured memory_bytes: 44208
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	int nA, nB, nC;
	int ans=0;
	if(A==B && A==C){
		if(A%2){
			ans=0;
		}else{
			ans=-1;
		}
	}else{
		while(true){
			if(A%2 || B%2 || C%2){
				break;
			}
			nA = (B+C)/2;
			nB = (A+C)/2;
			nC = (A+B)/2;
			A = nA;
			B = nB;
			C = nC;
			ans++;
		}
	}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,cnt,ans,q[101010][2],bok[1010][1010],dep[1010][1010];
int f[1010],ma[1010],fir[101010],nxt[202020],to[202020];
int fl[4][2]={{0,-1},{0,1},{1,0},{-1,0}};
char s[1010][1010];
int id(int x,int y){ return (x-1)*m+y;}
int bfs(int x,int y)
{
	int fr=0,b=0;
	q[++b][0]=x;q[b][1]=y;bok[x][y]=1;dep[x][y]=0;
	while(fr<b)
	{
		x=q[++fr][0],y=q[fr][1];
		for(int i=0;i<=3;i++)
		{
			int xx=x+fl[i][0],yy=y+fl[i][1];
			if(xx<1||xx>n||yy<1||yy>m||bok[xx][yy]||s[xx][yy]=='#') continue;
			q[++b][0]=xx;q[b][1]=yy;
			bok[xx][yy]=1;dep[xx][yy]=dep[x][y]+1;
		}
	}
	for(int i=1;i<=b;i++)
	bok[q[i][0]][q[i][1]]=0;
	return dep[q[b][0]][q[b][1]];
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	if(s[i][j]=='.')
		ans=max(ans,bfs(i,j));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  while(true){
    int m,f,r;
    cin>>m>>f>>r;
    if(m==-1&&f==-1&&r==-1)break;
    if(m==-1||f==-1)cout<<"F"<<endl;
    else if(m+f>=80)cout<<"A"<<endl;
    else if(m+f>=65)cout<<"B"<<endl;
    else if(m+f>=50)cout<<"C"<<endl;
    else if(m+f>=30){
      if(r>=50)cout<<"C"<<endl;
      else cout<<"D"<<endl;
    }else cout<<"F"<<endl;

  }
}



Measured memory_bytes: 3080
S = input()
T = input()

ls = len(S)
lt = len(T)
left = -1

for i in range(ls-lt+1):
    for j in range(lt):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
       left = i
if left == -1:
    ans = "UNRESTORABLE"
else:
    ans = S[:left]+T+S[left+lt:]
    ans = ans.replace("?", "a")
print(ans)

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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

const int N = 2007;

int ans[N];

int X, Y;

inline int dist(int a, int b){
    return min(b-a, abs(X-a)+1+abs(Y-b));
}

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    int n;
    cin >> n >> X >> Y;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            ans[dist(i, j)]++;
        }
    }
    for(int i = 1; i < n; i++){
        cout << ans[i] << '\n';
    }

	return 0;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Jan 27 14:51:26 2019
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	var s string
	var K int
	fmt.Scan(&s, &K)

	bytes := make([]byte, 26)
	for i := range bytes {
		bytes[i] = 'a' + byte(i)
	}

	substrings := make([]string, 0)
	for _, b := range bytes {
		for i := range s {
			if s[i] == b {
				for j := 1; i+j <= len(s) && j <= 5; j++ {
					substrings = append(substrings, string(s[i:i+j]))
				}
			}
		}
	}
	sort.Strings(substrings)

	for i := range substrings {
		valid := true
		for j := i - 1; j >= 0; j-- {
			if substrings[i] == substrings[j] {
				valid = false
			}
		}
		if valid {
			K--
			if K == 0 {
				fmt.Println(substrings[i])
				return
			}
		}
	}
}


Measured memory_bytes: 2816
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int A, B, cnt = 0;

int main()
{
    cin >> A >> B;

    for (int i = A; i <= B; i++) {
        int n = i;
        if (n / 10000 == n % 10) {
            n -= n / 10000 * 10000;
            if (n / 1000 == n % 100 / 10) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
n, y = gets.split.map(&:to_i)

a = b = c = -1

valid = false
0.upto([y / 10_000, 2_000].min) do |i|
  break if valid

  0.upto(((y - 10_000 * i) / 5_000)) do |j|
    rest = y - 10_000 * i - 5_000 * j
    k = rest / 1_000
    valid = k && (i + j + k == n)

    if valid
      a, b, c = [i, j, k]
      break
    end
  end
end

puts [a, b, c].join(" ")


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

using namespace std;
using ll = long long;

int main() {
    int H, W;
    cin >> H >> W;
    vector<int> x{1, 1, 1, 0, -1, -1, -1, 0};
    vector<int> y{-1, 0, 1, 1, 1, 0, -1, -1};
    vector<vector<char> > inp(H,vector<char>(W));
    vector<vector<int> > outp(H,vector<int>(W,0));

    for(int i = 0; i < H; i++) {
        string S;
        cin >> S;
        for(int j = 0; j < W; j++) {
            inp.at(i).at(j) = S.at(j);
            for(int k = 0; k < 8; k++) {
                int nx = j + x.at(k);
                int ny = i + y.at(k);
                if(nx >= 0 && ny >= 0 && nx < W && ny < H && inp.at(i).at(j) == '#') {
                    outp.at(ny).at(nx)++;
                }
            }
        }
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(inp.at(i).at(j) == '.') {
                cout << outp.at(i).at(j);
            } else {
                cout << '#';
            }
        }
        cout << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<int> s(n+1),t(m+1);
	vector<vector<ll>> dp(n+1,vector<ll>(m+1,0));
	vector<vector<ll>> sum(n+1,vector<ll>(m+1,0));
	FOR(i,1,n+1){
		cin>>s[i];
	}
	FOR(j,1,m+1){
		cin>>t[j];
	}
	dp[0][0]=1;
	rep(i,n+1) sum[i][0]=1;
	rep(j,m+1) sum[0][j]=1;
	FOR(i,1,n+1)FOR(j,1,m+1){
		if(s[i]!=t[j]){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			sum[i][j]=(sum[i][j]+mod)%mod;
			continue;
		}
		dp[i][j]=sum[i-1][j-1]%mod;
		sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j];
		sum[i][j]=(sum[i][j]+mod)%mod;
	}
	cout<<sum[n][m]<<endl;
}

Measured memory_bytes: 62976
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;

    vector<int> L(K+1,0);
    vector<int> R(K+1,N+1);
    int cnt=0;
    int vac=0;
    for(int i=0; i<N; i++){
        if(vac>0){
            vac--;
        }else if(S[i]=='o'){
            cnt++;
            L[cnt]=i+1;
            vac=C;
        }
        if(cnt==K)break;
    }

    cnt=K;
    vac=0;
    for(int i=N-1; i>=0; i--){
        if(vac>0){
            vac--;
        }else if(S[i]=='o'){
            R[cnt]=i+1;
            vac=C;
            cnt--;
        }
        if(cnt==0)break;
    }

    //cout_vec(L);
    //cout_vec(R);

    for(int i=1; i<=K; i++){
        if(L[i]==R[i]){
            cout << L[i] << '\n';
        }
    }
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int main() {
	long long xx=100,x,ans=0;
	cin>>x;
	
	while(xx<x){
	    xx*=1.01;
	    ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b,c,ans[2]={0};
  for(;;){
    if(scanf("%d,%d,%d",&a,&b,&c) == EOF) break;
    if(c*c == a*a+b*b) ans[0]++;
    if(a == b) ans[1]++;
  }
  cout <<ans[0]<<endl<<ans[1]<<endl;
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    ll mod = 1e9 + 7;
    if(abs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }
    ll ans;
    if(abs(n-m) == 1) ans = 1;
    else ans = 2;
    rep(i,n){
        ans *= (i+1);
        ans %= mod;
    }
    rep(i,m){
        ans *= (i+1);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  int N, a, l, r;
  cin >> N;
  cin >> a;
  l = a;
  r = a;
  for( int i=1; i<N; i++ ){
    cin >> a;
    l = min( l, a );
    r = max( r, a );
  }
  cout << r - l << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>
#include<stack>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

//--------------
///#define DEBUG
//--------------

#ifdef DEBUG
	#define debugprint(x) cout<<x<<" "
	#define debugendl cout<<endl
	#define debug(x) x
#else
	#define debugprint(x)
	#define debugendl
	#define debug(x)
#endif

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	zahyo operator*(int t){
		zahyo temp;
		temp.x=this->x*t;
		temp.y=this->y*t;
		return temp;
	}
	zahyo operator%(int t){
		zahyo temp(this->x%t,this->y%t);
		return temp;
	}
	zahyo operator/(int t){
		zahyo temp(this->x/t,this->y/t);
		return temp;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

vector<int> edge[200000];
int arrived[200000];
int ans=0;
void check(int a){
	//cout<<"c("<<a<<")"<<endl;
	if(arrived[a]==-1){
		arrived[a]=1;
		ans++;
		for(int i=0;i<edge[a].size();i++){
			check(edge[a][i]);
		}
	}
}



int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	for(int i=0;i<n;i++){
		arrived[i]=-1;
	}
	int temp=0;
	for(int i=0;i<n;i++){
		if(arrived[i]==-1){
			ans=0;
			check(i);
			temp=max(temp,ans);
		}
	}
	cout<<temp<<endl;
}


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

int main()
{
	int h, w, dd[] = {0, 1, 0, -1, 0};
	cin >> h >> w;
	vector<string> s(h);
	for (auto &i : s)
	{
		cin >> i;
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (s[i][j] == '#')
			{
				int count = 0;
				for (int k = 0; k < 4; k++)
				{
					int ni = i + dd[k], nj = j + dd[k + 1];
					if ((0 <= ni && ni < h && 0 <= nj && nj < w) && s[ni][nj] == '#')
					{
						count++;
					}
				}
				if (count == 0)
				{
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets().to_i
s = Array.new(n,0)
for i in 0..n-1
	s[i] = gets().to_i
end

s.sort!

ichi = Array.new(n,0)

sum = 0
ten = 0

for j in 0..n-1
	sum = sum + s[j]
	ichi[j] = s[j] % 10
end

if sum % 10 == 0
	for k in 0..n-1
		if ichi[k] != 0
			ten = sum - s[k]
			break
		end
	end
else
	ten = sum
end

print(ten,"\n")

Measured memory_bytes: 1788
n=int(input())
a=list(map(int,input().split()))
if n<=3:print(max(a));exit()
if n&1:
  dp=[3*[-(10**20)]for _ in range(n)]
  dp[0][0]=a[0]
  for i in range(1,n):
    if i%2==0:
      dp[i][0]=dp[i-2][0]+a[i]
      if i>=3:dp[i][2]=max(dp[i-2][2]+a[i],dp[i-3][1]+a[i])
      else:dp[i][2]=a[i]
    else:
      if i>=3:dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i])
      else:dp[i][1]=a[i]
  print(max(dp[-1][2],dp[-2][1],dp[-3][0]))
else:
  b=[a[0]]
  c=[a[1]]
  for i in range(2,n):
    if i%2==0:b.append(b[-1]+a[i])
    else:c.append(c[-1]+a[i])
  ans=max(b[-1],c[-1])
  for i in range(n//2-1):
    ans=max(ans,b[i]+c[-1]-c[i])
  print(ans)


Measured memory_bytes: 52180
q, h, s, d = map(int, input().split())
n = int(input())
l = min(q * 8, h * 4, s * 2, d)
if n % 2 == 0:
    print(l * n // 2)
else:
    if l == d:
        l2 = min(q * 4, h * 2, s)
        print(n // 2 * l + l2)
    else:
        print(l * n // 2)

Measured memory_bytes: 9080
program FizzBuzz
      implicit none
      
      integer(8) N,S,i
      read(*,*) N
      S=0
      do i =1, N
      if (mod(i,5)==0.or.mod(i,3)==0) then
            go to 1
      else
            S=S+i
      1 end if
      end do
      
      write(*,'(i0)') S
      stop 
      end program FizzBuzz




Measured memory_bytes: 2928
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

long long com(long long n,long long k){
	
}
long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}

class Point{
public:
	long long x;
	long long y;
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string o,e;
	cin>>o>>e;
	string ans;
	int i=0;
	while(i<(o.length()+e.length())){
		if(i%2==0)ans+=o[i/2];
		if(i%2==1)ans+=e[i/2];
		i++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
class Main
{
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		int n = sc.nextInt();
		int max = -1000000000, min = sc.nextInt();
		int in;
		for( int ct = 1 ; ct < n ; ct++ ){
			in = sc.nextInt();
			if( in-min > max )max = in-min;
			if( in < min )min = in;
		}
		System.out.printf( "%d\n" , max );
	}
}

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

ll ctoi(char c) {
  if (c == '0') {return 0;}
  if (c == '1') {return 1;}
  if (c == '2') {return 2;}
  if (c == '3') {return 3;}
  if (c == '4') {return 4;}
  if (c == '5') {return 5;}
  if (c == '6') {return 6;}
  if (c == '7') {return 7;}
  if (c == '8') {return 8;}
  if (c == '9') {return 9;}
} 

int main() {
  ll N, P; cin >> N >> P;
  string s; cin >> s;
  ll m[N];
  ll modpow = 1;
  if (P != 2 && P != 5) {
  for (ll i = N-1; i >= 0; i--) {
    m[i] = (ctoi(s[i]) * modpow) % P;
    modpow = (modpow * 10) % P;
  }
  ll msum[N+1];
  msum[0] = 0;
  map<ll,ll> count;
  count[0]++;
  for (ll i = 1; i <= N; i++) {
    msum[i] = (msum[i-1] + m[i-1]) % P;
    count[msum[i]]++;
  }
  ll res = 0;
  for (ll i = 0; i < P; i++) {
    res += count[i]*(count[i]-1)/2;
  }
  cout << res << endl;
  }
  if (P == 2) {
    ll res = 0;
    for (ll i = 0; i < N; i++) {
      if (ctoi(s[i]) % 2 == 0) {res += (i+1);}
    }
    cout << res << endl;
  }
  if (P == 5) {
    ll res = 0;
    for (ll i = 0; i < N; i++) {
      if (ctoi(s[i])%5 == 0) {res += (i+1);}
    }
    cout << res << endl;
  }
}

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

typedef long long int ll;
#define ent cout << "\n"
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define pair < ll, ll > pp
#define f(a, b) for(auto i = a;i < b;i++)
#define rev_f(a, b) for(auto i = b;i >= a;i--)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define st(x) sort(x.begin(), x.end()) 
#define rv(x) reverse(x.begin(), x.end()) 
#define cintc() ll tc;while(tc--) 
#define deb(x) cout << x << "\n";
#define cin(a) ll a; cin >> a;
#define cin2() ll a, b; cin >> a >> b
#define cin3() ll a, b, c; cin >> a >> b >> c
#define cinn(vect, n) def_v vect(n); f(0, n) cin >> vect[i]
#define coutn(vect, n)  f(0, n) {cout << vect[i] << "";} cout << " ";

typedef vector < ll > def_v;
typedef tuple< ll, ll, ll> def_tuple;
ll mod = 1e9 + 7,cnt = 0;

vector < ll > bfs(vector < ll > graph[], vector < ll > vect, ll start, ll flag, ll n)
{

    ll vis[n + 1] = {0};
    vis[start] = 1;
    queue < ll > q;
    q.push(start);
    while(!q.empty())
    {

        ll start = q.front();
        q.pop();
        auto size = ll(graph[start].size());
        for(ll j = 0;j < size;j++)
        {
            ll x = graph[start][j];
            if(!vis[x])
            {
                vis[x] = 1;
                if(x == 1 && flag == 2)
                {
                    flag = 2;
                }
                else
                    q.push(x);
                vect[x] = flag;
            }
        }
    }

    return vect;
}

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

    map < string , ll > hm;
    f(0, n)
    {

    	string str;
    	cin >> str;

    	if(hm[str] == 0)
    		hm[str] = 1;
    	else
    		hm[str]++;

    }
    cout << hm.size();  
    ent; 
    return 0;
}

Measured memory_bytes: 19180
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
#define N 200009
#define LL long long
#define INF 0x3f3f3f3f
#define mymin(x,y) (x>=y?y:x)
#define mymax(x,y) (x>=y?x:y)
int A[N], tong[N], be[N], af[N], mark[N];
int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	LL n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> A[i];
	}
	for(int i = 1; i <= n; i++){
		if(tong[A[i]] == 0) tong[A[i]] = i;
		else{
			be[i] = tong[A[i]];
			af[tong[A[i]]] = i;
			tong[A[i]] = i;
		}
	}
	for(int i = 1; i <= n; i++){
		if(be[i] == 0 && af[i] != 0){
			be[i] = tong[A[i]];
			af[be[i]] = i;
		}
	}
	LL r = 1;
	int pos = 1;
	memset(mark, 0, sizeof(mark));
	while(!mark[pos]){
	//	cout << "debug1: round: " << r << " pos: " << pos << endl;
		mark[pos] = r;
		if(af[pos] == 0){
			r++;   
			pos++;
				if(pos > n) pos = 1, r++;
		}
		else if(af[pos] < pos){
			r++;
			pos = af[pos] + 1;
		}	
		else if(af[pos] == n){
			r++;
			pos = 1;
		}
		else{
			pos = af[pos] + 1;
		}
	}
	if(k <= r){
		r = 1;
		pos = 1;
		while(r < k){
			if(af[pos] == 0){
				r++;   
				pos++;
				if(pos > n) pos = 1, r++;
			}
			else if(af[pos] < pos){
				r++;
				pos = af[pos] + 1;
			}	
			else if(af[pos] == n){
				r++;
				pos = 1;
			}
			else{
				pos = af[pos] + 1;
			}
		}
		while(pos <= n){
			while(pos <= n && af[pos] != 0 && af[pos] > pos){
				pos = af[pos] + 1;
			}
			if(pos <= n)
				cout << A[pos] << " ";
			pos++;
		}
		return 0;
	}
	int res = ((k - r) % (r - (LL)mark[pos]));
	r = 0;
	while(r < res){
		if(af[pos] == 0){
			r++;   
			pos++;
				if(pos > n) pos = 1, r++;
		}
		else if(af[pos] < pos){
			r++;
			pos = af[pos] + 1;
		}	
		else if(af[pos] == n){
			r++;
			pos = 1;
		}
		else{
			pos = af[pos] + 1;
		}
	}
	while(pos <= n){
		while(pos <= n && af[pos] != 0 && af[pos] > pos){
			pos = af[pos] + 1;
		}
		if(pos <= n)
			cout << A[pos] << " ";
		pos++;
	}
	return 0;
}

	//		cout << "debug2: round: " << r << " pos: " << pos << endl;
	//		cout << "debug3: round: " << r << " pos: " << pos << endl;
				//cout << "out: " << A[pos] << endl;

Measured memory_bytes: 7556
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("panic read line");
    let splitted_input: Vec<i32> = input.split_whitespace()
                                .map(|s| s.parse().expect("panic parse"))
                                .collect();
    let n = splitted_input[0];
    let y = splitted_input[1];

    for i in 0..n+1 {
        for j in 0..n+1-i {
            let k = n-i-j;
            let sum = i*10000 + j*5000 + k*1000;
            if sum == y {
                println!("{} {} {}", i, j, k);
                return
            }

        }
    }

    println!("{} {} {}", -1, -1, -1)
}


Measured memory_bytes: 2144
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	A_fix
# CreatedDate:  2020-09-27 15:12:42 +0900
# LastModified: 2020-09-27 15:23:26 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def Possible_or_Impossible(visited, H, W):
    for v in visited:
        if -1 in v:
            return 0
    return 1



def DFS(visited, maze, H, W, u):
    visited[u[0]][u[1]] = 1
    if visited[u[0]+1][u[1]] == -1 and maze[u[0]+1][u[1]] == 1:
        if DFS(visited, maze, H, W, [u[0]+1, u[1]]) == 1:
            return 1
        visited[u[0]+1][u[1]] = -1

    if visited[u[0]][u[1]+1] == -1 and maze[u[0]][u[1]+1] == 1:
        if DFS(visited, maze, H, W, [u[0], u[1]+1]) == 1:
            return 1
        visited[u[0]][u[1]+1] = -1

    if Possible_or_Impossible(visited, H, W) == 1:
        return 1


def main():
    H, W = map(int, input().split())
    maze = [[0]*(W+2)]
    visited = [[0]*(W+2)]
    for _ in range(H):
        S = input()
        S = [0 if s == "." else 1 for s in S]
        V = [0 if s == 0 else -1 for s in S]
        S.insert(0, 0)
        V.insert(0, 0)
        S.append(0)
        V.append(0)
        maze.append(S)
        visited.append(V)
    maze.append([0]*(W+2))
    visited.append([0]*(W+2))
    if DFS(visited, maze, H, W, [1, 1]) == 1:
        print("Possible")
    else:
        print("Impossible")



if __name__ == "__main__":
    main()


Measured memory_bytes: 9344
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: usize, a: [i64; n]);
    let mut init_check = true;
    for i in 1..n {
        if a[i] < a[i - 1] {
            init_check = false;
            break;
        }
    }
    if init_check {
        println!("0");
        return;
    }

    let mut max_i = 0;
    let mut min_i = 0;
    for i in 0..n {
        if a[i] > a[max_i] {
            max_i = i;
        }
        if a[i] < a[min_i] {
            min_i = i;
        }
    }

    let mut a = a;
    let mut ans = vec![];
    if a[max_i].abs() >= a[min_i].abs() {
        assert!(a[max_i] > 0);
        for i in 0..n {
            if a[i] < 0 {
                a[i] += a[max_i];
                ans.push((i, max_i));
            }
        }
        for i in 1..n {
            a[i] += a[i - 1];
            ans.push((i, i - 1));
            assert!(a[i - 1] <= a[i]);
        }
    } else {
        assert!(a[min_i] < 0);
        for i in 0..n {
            if a[i] > 0 {
                a[i] += a[min_i];
                ans.push((i, min_i));
            }
        }
        for i in (1..n).rev() {
            a[i - 1] += a[i];
            ans.push((i - 1, i));
            assert!(a[i - 1] <= a[i]);
        }
    }

    println!("{}", ans.len());
    for &(y, x) in ans.iter() {
        println!("{} {}", x + 1, y + 1);
    }
}


Measured memory_bytes: 4352
import static java.lang.System.*;
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static char[] d = {'>','<','^','v'};
	static int[] dx = {1,-1,0,0};
	static int[] dy = {0,0,-1,1};

	public static void main(String[] args) {
		while(sc.hasNext()) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if (h==0 && w==0) break;
			
			char[][] map = new char[h][w];
			for (int i=0; i<h; i++) {
				String s = sc.next();
				for (int j=0; j<w; j++) {
					map[i][j] = s.charAt(j);
				}
			}
			
			boolean[][] memo = new boolean[h][w];
			int x = 0;
			int y = 0;
			boolean loop = false;
			memo[y][x] = true;
			loop1: while (map[y][x] != '.') {
				for (int i=0; i<4; i++) {
					if (map[y][x]==d[i]) {
						x += dx[i]; y += dy[i];
						if (memo[y][x]) {
							loop = true;
							break loop1;
						}
						else memo[y][x] = true;
					}
				}
			}
			
			out.println(loop?"LOOP":x+" "+y);
		}
	}
}



Measured memory_bytes: 28864
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
  int h,w;
  while(1) {
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    if(h == 0 || w == 0) continue;
    REP(i,h) {
      if(i % 2 == 0) {
        REP(j,w) {
          if(j % 2 == 0) {
            cout << "#";
          } else {
            cout << ".";
          }
        }
        cout << endl;
      } else {
        REP(j,w) {
          if(j % 2 == 0) {
            cout << ".";
          } else {
            cout << "#";
          }
        }
        cout << endl;
      }
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e15+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;

int t=1;
//in t;
int tt=0;
while(t--){
int n;in n;
int sum=0;
for(int i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0) sum+=i;
}
out sum;
}
return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 3652
use proconio::input;


fn solve(s: String, t: String) {
    let mut ans = 0;

    for i in 0..3 {
        if s[i..i+1] == t[i..i+1] {
            ans += 1
        }
    }

    println!("{}", ans);
}




fn main() {
    input! {
        s: String,
        t: String,
    }

    solve(s, t);
}


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

int main(){
	string s;
	cin >> s;
	int num1 = (s[0]-'0')*10+s[1]-'0';
	int num2 = (s[2]-'0')*10+s[3]-'0';
	int f1 = 0,f2 = 0;
	if(num1<=12&&num1>=1){
		f1 = 1;
	}
	if(num2<=12&&num2>=1){
		f2 = 1;
	}
	if(f1&&f2){
		cout<<"AMBIGUOUS"<<endl;
	}
	else if(f1){
		cout<<"MMYY"<<endl;
	}
	else if(f2){
		cout<<"YYMM"<<endl;
	}
	else{
		cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int N,a[3][101],i,j;
scanf("%d",&N);
for(j = 1;j <= N;j++) scanf("%d",&a[1][j]);
for(j = 1;j <= N;j++) scanf("%d",&a[2][j]);

int ans = 0;
for(i = 1;i <= N;i++){
int temp = 0;

for(j = 1;j <= i;j++) temp += a[1][j];
for(j = i;j <= N;j++) temp += a[2][j];

if(temp >= ans) ans = temp;

}

printf("%d",ans);


}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    
    int ans = 0;
    
    for(int i = 1; i <= n - 2; i++){
        int max_e, min_e;
        max_e = max({p[i - 1], p[i], p[i + 1]});
        min_e = min({p[i - 1], p[i], p[i + 1]});
        if(p[i] == max_e || p[i] == min_e){
            continue;
        }
        ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define lmax LLONG_MAX
#define lmin LLONG_MIN
#define f(i,a,b) for(long long i=a;i<b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define tc long long test;cin>>test;while(test--)
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define output(a,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<endl;
#define endl "\n"
#define mem(a) memset(a,-1,sizeof(a))
#define ll long long

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

        string s;
        cin>>s;

        ll n=s.size();

        if(s[n-1]=='s') cout<<s<<"es"<<endl;
        else cout<<s+'s'<<endl;

    return 0; 
}










Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vsi vector<pair<int,int> >;
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
using namespace std;
int n,m;
int a[100000];
long long ans=0;
priority_queue<int> q;
int main(){
	cin>>n>>m;
	rep(i,n){
		cin>>a[i];
		q.push(a[i]);
	}
	while(m){
		int k=q.top();
 		q.pop();
  		k/=2;
   		q.push(k);
   		m--;
	}while(!q.empty()){
		ans+=q.top();
		q.pop();
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 1148
import math
a, b, h, m = map( float, input().split() )

theta_a = 2 * math.pi * ( h + m / 60 ) / 12
theta_b = 2 * math.pi * m / 60

print( math.sqrt( a ** 2 + b ** 2 - 2 * a * b * math.cos( theta_a - theta_b ) ) )

Measured memory_bytes: 9428
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
signed main(){
  ll n,a[100000],m=0;
  ll ans[100000],sum[1000000];
  cin>>n;
  for(int i=0;i<n;i++){
   cin>>a[i];
    m += a[i];
    sum[i] = m;
  }
  for(int i=0;i<n;i++){
   ans[i] = abs(2*sum[i]-sum[n-1]);
  }
  sort(ans,ans+n);
  cout<<ans[0]<<"\n";
  return(0);
}

Measured memory_bytes: 2304