akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    int H,W,h,w,c;
    cin >>H >> W;
    cin >> h >> w;
    c=H*W-h*w-h*(W-w)-w*(H-h);
    if(w==W||h==H)
    {
        c=0;
    }
    cout << c;
    return 0;
}
    

Measured memory_bytes: 256
#include<cstdio>
int main(){
        int n,a[100000],b[100000],max=0,min=1000000000,m;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
                scanf("%d",&a[i]);
                if(a[i]>max){
                        max=a[i];
                }
        }
        for(int i=0;i<n;i++){
                if(max>=2*a[i]){
                        b[i]=max-2*a[i];
                }
                else{
                        b[i]=2*a[i]-max;
                }
                if(min>=b[i]){
                        min=b[i];
                        m=i;
                }
        }
        printf("%d %d",max,a[m]);
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		// map????????????
		Map<Character, Integer> answer = new HashMap<Character, Integer>();
		char[] keyList = "abcdefghijklmnopqrstuvwxyz".toCharArray();
		for (char key : keyList) {
			answer.put(key, 0);
		}
		String input;
		while ((input = br.readLine()) != null) {
			char[] list = input.toLowerCase().toCharArray();

			for(char character : list) {
				if (answer.containsKey(character)) {
					answer.put(character, answer.get(character) + 1);
				}
			}
		}

		for (char character : keyList) {
			System.out.println(character + " : " + answer.get(character));
		}
	}
}

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

#define int unsigned long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    
    int tento=0;
    REP(i,0,n){
        REP(j,i,n){
            if(a[i]>a[j]) tento++;
        }
    }
    int zentento=0;
    REP(i,0,n){
        REP(j,0,n){
            if(a[i]>a[j]) zentento++;
        }
    }
    int keisu=(k*(k+1)/2)%MOD;
    int zenkeisu=(k*(k-1)/2)%MOD;
    cout<<((tento*keisu)%MOD + ((zentento-tento)*zenkeisu)%MOD)%MOD<<endl;
    return 0;
}



Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()
	N := len(s)

	r := 0
	b := 0
	for i := 0; i < N; i++ {
		if s[i] == '0' {
			r++
		} else {
			b++
		}
	}
	out(min(r, b) * 2)
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    if(n%2 == 0) cout<<n/2<<endl;
    else cout<<n/2+1<<endl;
}

Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
#
# A, B, C, X = [int(sys.stdin.readline()) for _ in range(4)]
# ans = 0
# for a in range(A+1):
#     for b in range(B+1):
#         for c in range(C+1):
#             ans += a*500+b*100+c*50 == X
#
# print(ans)


a, b = list(map(int, sys.stdin.readline().split()))
ok = False
for i in range(1000):
    ok |= i * i == int(str(a) + str(b))
if ok:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 13552
A, B, C, X, Y = gets.split.map(&:to_i)

if C * 2 <= A || C * 2 <= B then
  if X >= Y && C * 2 <= A then
    ans = (X * 2) * C
  elsif Y >= X && C * 2 <= B then
    ans = (Y * 2) * C
  elsif Y >= X && C * 2 <= A then
    tmp = (X * 2) * C
    ans = tmp + (Y - X) * B
  elsif X >= Y && C * 2 <= B then
    tmp = (Y * 2) * C
    ans = tmp + (X - Y) * A
  end
elsif (A + B) / 2 >= C then
  if X >= Y then
    tmp = C * (Y * 2)
    ans = tmp + A * (X - Y)
  elsif Y >= X then
    tmp = C * (X * 2)
    ans = tmp + B * (Y - X)
  end
else
  ans = A * X + B * Y
end

puts ans


Measured memory_bytes: 1916
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n
l1 ... l2n

n 100
l 100
 */
int n;
int l[200];

int main(){
  cin>>n;
  
  REP(i,2*n){
    cin>>l[i];
  }

  sort(l,l+2*n);

  int ans=0;
  REP(i,n){
    ans+=l[2*i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m=0,l=0,num=0,sum=0;

        cin>>n;
        while(l<n){
            l++;
            if(l%3!=0&&l%5!=0){
                m+=l;}


        }sum=sum+m;
       cout << sum<<endl;



}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define _start  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb 		push_back
#define ss 		second
#define ff 		first
#define ll		long long
#define int     long long
#define mk      make_pair
#define ld 		long double
#define vi 		vector<int>
#define pi		pair<int,int>
#define mod 	1000000007
#define pqg     priority_queue<int>
#define pqs     priority_queue<int,vi,greater<int> >
#define forn(n) for(int i=0;i<n;i++)
#define w(t) 	int t; cin>>t; while(t--)
#define kick(t) int t; cin>>t; for(int p=0;p<t;p++)
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> oset;
ll powmod(ll base,ll exp,ll MOD=mod){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}

const int MAX=300005;
int xs[MAX],ys[MAX];

int32_t main(){
    _start
    int h,w,m;
    cin>>h>>w>>m;

    map<pi,int> points;
    int xmax=0,ymax=0;
    forn(m) {
        int a, b;
        cin >> a >> b;
        xs[a]++;
        ys[b]++;
        points[mk(a,b)]=i;
        xmax=max(xmax,xs[a]);
        ymax=max(ymax,ys[b]);
    }
    vector<int> xmx,ymx;
    for(int i=1;i<=h;i++) {
        if(xs[i]==xmax){
            xmx.pb(i);
        }
    }
    for(int i=1;i<=w;i++) {
        if(ys[i]==ymax){
            ymx.pb(i);
        }
    }
    int mx=xmax+ymax-1;
    for(auto x:xmx){
        for(auto y:ymx){
            if(!points.count(mk(x,y))){
                mx++;
                break;
            }
        }
        if(mx==xmax+ymax)
            break;
    }
    cout<<mx;
}

Measured memory_bytes: 34928
class dice():
    def __init__(self,labels):
        self.l=labels

    def zen(self,a,b):
        x1=self.l[0]
        x2=self.l[1]
        x3=self.l[2]
        x4=self.l[3]
        x5=self.l[4]
        x6=self.l[5]
        if (a,b)==(x1,x2) or (a,b)==(x2,x6) or (a,b)==(x6,x5) or (a,b)==(x5,x1):
            print(x3)
        elif (a,b)==(x3,x2) or (a,b)==(x2,x4) or (a,b)==(x4,x5) or (a,b)==(x5,x3):
            print(x6)
        elif (a,b)==(x6,x2) or (a,b)==(x2,x1) or (a,b)==(x1,x5) or (a,b)==(x5,x6):
            print(x4)
        elif (a,b)==(x3,x1) or (a,b)==(x1,x4) or (a,b)==(x4,x6) or (a,b)==(x6,x3):
            print(x2)
        elif (a,b)==(x3,x6) or (a,b)==(x6,x4) or (a,b)==(x4,x1) or (a,b)==(x1,x3):
            print(x5)
        elif (a,b)==(x4,x2) or (a,b)==(x2,x3) or (a,b)==(x3,x5) or (a,b)==(x5,x4):
            print(x1)

dice=dice([int(i) for i in input().split()])
n=int(input())
for i in range(n):
    a,b=map(int,input().split())
    dice.zen(a,b)



Measured memory_bytes: 5616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program_C
{
  static void Main(string[] args)
  {
    var N = Int32.Parse(Console.ReadLine());
    var lst = new List<int>();
    var m1 = -1;
    var m2 = -1;
    var mi = -1;
    for(var i = 0; i < N; i++)
    {
       var n = Int32.Parse(Console.ReadLine());
       if(m1 <= n)
       {
       	 m2 = m1;
         m1 = n;
         mi = i;
       }
       else if(m2 < n)
       {
         m2 = n;
       }
    }
    
    for(var i = 0; i < N; i++)
    {
    	Console.WriteLine( mi == i ? m2 : m1);
    }
  }
}



Measured memory_bytes: 18504
n, k = gets.split(' ').map(&:to_i)
ranges = k.times.map { gets.split(' ').map(&:to_i) }

m = 998244353

fs = [1]
cum = [1]
(1...n).each do |i|
  f = 0
  ranges.each do |r|
    f += cum[i - r[0]] if i - r[0] >= 0
    f -= cum[i - (r[1] + 1)] if i - (r[1] + 1) >= 0
    f %= m
  end
  fs << f
  cum << ((cum.last || 0) + f) % m
end

puts fs.last


Measured memory_bytes: 17536
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
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/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  ll n;
  cin>>n;
  v(ll) a(n);
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  ll ans=MX;
  ll sumex=0;
  for(int i=0;i<n-1;i++){
    sumex+=a[i];
    sum-=a[i];
    mins(ans,abs(sumex-sum));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4784
D=int(input())
c=[int(i) for i in input().split()]
a=[]
for i in range(D):
    a.append([int(i) for i in input().split()])

last=[0 for i in range(26)]
zoku=0    
for d in range(D):
    print(a[d].index(max(a[d]))+1)

Measured memory_bytes: 68084
#include <iostream>
#include <cstdio>

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(){
    string s;
    while(cin >> s){
        string a = "Z";
        for(char c:s){
            if(c != 'A' && c != 'Z') continue;
            if(a.back() != c) a += c;
        }
        a = a.substr(1,s.size());
        if(a.back() == 'A') a = a.substr(0,a.size()-1);
        if(a == "") a = "-1";
        cout << a << endl;
    }
}

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

int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  int result = 0;
  if(op == "+"){
    result = a + b;
  }
  else{
    result = a - b;
  }
  cout << result;
}


Measured memory_bytes: 3596
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
x = I()
ans = 1
for b in range(2,1001):
    for p in range(2,24):
        if b**p <= x:
            ans = max(ans,b**p)
        else:
            break
print(ans)


Measured memory_bytes: 10300
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: i64,
    }

    let ans: i64 = (1..N + 1).filter(|n| n % 3 != 0 && n % 5 != 0).sum();
    println!("{}", ans);
}


Measured memory_bytes: 2068
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <utility>
#include <unordered_map>
#define ll long long int
#define pb push_back
#define mp make_pair


using namespace std;


void solve(){
    ll n;
    cin>>n;
    // cout<<(1000-n%1000)%1000<<endl;
    unordered_map<string,ll> map;

    while(n-->0){
        string str;
        cin>>str;
        map[str]++;
    }

    cout<<"AC"<<" "<<"x"<<" "<<map["AC"]<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<map["WA"]<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<map["TLE"]<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<map["RE"]<<endl;
}

int main(){
    // int t; cin>>t;

    solve();

    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
set<int>a;
int main()
{
    int n,choose,temp,l,r;
    cin >> n;
    while (n--)
    {
        cin >> choose;
        switch (choose)
        {
        case 0:
            cin >> temp;
            a.insert(temp);
            cout << a.size() << endl;
            break;
        case 1:
            cin >> temp;
            if (a.find(temp) == a.end())cout << 0 << endl;
            else cout << 1 << endl;
            break;
        case 2:
            cin >> temp;
            a.erase(temp);
            break;
        case 3:
            cin >> l >> r;
            set<int>::iterator begin, end;
            begin = a.lower_bound(l);
            end = a.upper_bound(r);
            for (; begin != end; begin++)
            {
                cout << *begin << endl;
            }
        }
    }
    
}


Measured memory_bytes: 12356
def main():
	n,l = map(int,input().split())
	apple = list(range(1,n+1))
	taste = []
	for i in range(1,n+1):
		taste.append(l+i-1)
	# print(taste)
	taste_abs = []
	for i in range(len(taste)):
		taste_abs.append(abs(taste[i]))
	# print(taste_abs)
	if min(taste_abs) == 0:
		print(sum(taste))
	else:
		taste.remove(taste[taste_abs.index(min(taste_abs))])
		print(sum(taste))

if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] data = new int[3];

    for (int i = 0; i < 3; i++) {
      data[i] = sc.nextInt();
    }

    Arrays.sort(data);
    int gap = data[2]-data[1] + data[2]-data[0];


    if (gap%2 == 0) {
      System.out.println(gap/2);
    } else {
      System.out.println((gap+1)/2+1);
    }

  }

}


Measured memory_bytes: 23764
#include <iostream>

int main() {
	bool a=true, b = true , c = true;
	int n;
	std::cin >> n;
	if (n == 1) {
		a = false;
	}
	if (n == 2) {
		b = false;
	}
	if (n == 3) {
		c = false;
	}
	std::cin >> n;
	if (n == 1) {
		a = false;
	}
	if (n == 2) {
		b = false;
	}
	if (n == 3) {
		c = false;
	}
	if (a) {
		std::cout << 1 << std::endl;
	}
	if (b) {
		std::cout << 2 << std::endl;
	}
	if (c) {
		std::cout << 3 << std::endl;
	}
}


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

int main() {
  int N, K, S;
  cin >> N >> K;
  S = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    if (K - x < x)
      S += (K - x);
    
    else
      S += x;
  }
  
  cout << 2 * S;
}

Measured memory_bytes: 256
import sys
a, b = map(int, input().split())
if b-a >= 2019:
    print(0)
    sys.exit()

ans = 2018
for i in range(a, b):
    for j in range(i+1, b+1):
        mod = (i % 2019)*(j % 2019) % 2019
        if ans > mod:
            ans = mod

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

using namespace std;

main()
{
  fast;
  int n,f=0;
  cin>>n;
  while (n)
  {
    if ((n%10)==7)
      f=1;
    n/=10;
  }
  if (f)
    cout<<"Yes\n";
  else
    cout<<"No\n";
}


Measured memory_bytes: 3640
// D - 桁和

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll f(ll b, ll n) {
	if (n < b) {
		return n;
	}

	return f(b, n / b) + n % b;
}

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

	if (n == s) {
		cout << s + 1 << endl;
		return 0;
	}

	for (ll b=2; b*b<=n; b++) {
		if (f(b, n) == s) {
			cout << b << endl;
			return 0;
		}
	}

	ll min_b = INF;

	for (ll p=1; p*p < n; p++) {
		ll b = (n - s) / p + 1;
		if (b < 2) continue;
		if (f(b, n) == s) {
			min_b = min(min_b, b);
		}
	}

	ll ans;
	if (min_b == INF) ans = -1;
	else ans = min_b;

	cout << ans << endl;

	return 0;
}

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

int H, W;
vector<string> G;
vector<vector<int>> visited;
vector<int> dx = { 0, 0, -1, 1 };
vector<int> dy = { 1, -1, 0, 0 };
queue<vector<int>> tovisit;

void bfs() {
  int y = tovisit.front().at(0);
  int x = tovisit.front().at(1);
  tovisit.pop();
  for (int i = 0; i < 4; i++) {
    int ny = y + dy.at(i);
    int nx = x + dx.at(i);
    if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
    if (G.at(ny).at(nx) == '#') continue;
    if (visited.at(ny).at(nx) != -1) continue;
    visited.at(ny).at(nx) = visited.at(y).at(x) + 1;
    tovisit.push({ ny, nx });
  }
}

int main() {
  cin >> H >> W;
  G.resize(H);
  for (int i = 0; i < H; i++) {
    string S; cin >> S;
    G.at(i) = S;
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (G.at(i).at(j) == '#') continue;
      visited = vector<vector<int>>(H, vector<int>(W, -1));
      tovisit.push({ i, j });
      visited.at(i).at(j) = 0;
      while (!tovisit.empty()) bfs();
      int tmp = 0;
      for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
          tmp = max(tmp, visited.at(y).at(x));
        }
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}


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

int main(void){

    int N , A[100];
    double sum=0 , M;
    int count=0;
    
    cin >> N >> M;
    for(int i=0 ; i<N ; i++){
        cin >> A[i];
        sum += A[i];
    }
    
    double B = sum/(4*M);
    
    for(int i=0 ; i<N ; i++) {
        if(A[i]>=B) count++;
    }
    
    if(count>=M)    cout << "Yes\n";
    else cout << "No\n";

    return 0;
}



Measured memory_bytes: 256
let j,u,k,e,r="overflow",read_line,int_of_string,print_endline,String.length;;let g s=let n=r s in let rec($)i a=if i=n then a else(i+1)$(s.[i]::a)in 0$[]and h c=Char.code c-48;;let(&)v w=let f x=if x<=9then(x,0)else(x mod 10,1)in let rec(^)o=function|([],[],1)->1::o|([],[],_)->o|(a::b,[],z)->let s,t=f(h a+z)in(s::o)^(b,[],t)|([],c::d,z)->let s,t=f(h c+z)in(s::o)^([],d,t)|(a::b,c::d,z)->let s,t=f(h a+h c+z)in(s::o)^(b,d,t)in[]^(g v,g w,0);;let n=read_int();;let rec f i=if i<n then(let x=u()and y=u()in let s=r x and t=r y in if s>80||t>80then e j else if s<10&&t<10then Printf.printf"%d
"(k x+k y)else(let z=x&y in if List.length z>80then e j else(List.iter(fun e->print_int e)z;print_newline()));f(i+1));;f 0

Measured memory_bytes: 2292
#coding:utf-8

s = input()
t = input()
n = len(s)

def rot(string):
    string = string[n-1] + string[:n-1]
    return string

for i in range(n):
    if s == t:
        print("Yes")
        break
    s = rot(s)
else:
    print("No")



Measured memory_bytes: 2940
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N;
  cin >> N;
  int D[N];
  rep(i,N){
    cin >> D[i];
  }
  sort(D,D+N);
  int M;
  cin >> M;
  int T[M];
  rep(i,M){
    cin >> T[i];
  }
  sort(T,T+M);
  int index=0;
  rep(i,N){
    if(D[i]==T[index]) index++;
    if(index==M){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    int h,w;
    cin >> h >> w;
    char f[h][w];
    int d[h][w];
    int cnt = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> f[i][j];
            if(f[i][j] == '#') cnt++;
            d[i][j] = -1;
        }
    }
    int sx = 0,sy = 0, gx = w-1, gy = h-1;
    int dx[4] = {-1,0,0,1};
    int dy[4] = {0,-1,1,0};
    queue<P> q;
    q.push(make_pair(sx,sy));
    d[0][0] = 0;
    while(!q.empty()){
        P p = q.front(); q.pop();
        int x = p.first,y = p.second;
        for(int i = 0; i < 4; i++){
            int nx = x + dx[i],ny = y + dy[i];
            if(nx >= 0 && nx < w && ny >= 0 && ny < h && d[ny][nx] == -1 && f[ny][nx] != '#'){
                d[ny][nx] = d[y][x] + 1;
                q.push(make_pair(nx,ny));
            }
        }
    }
    if(d[h-1][w-1] == -1){
        cout << -1 << endl;
    }else{
        cout << h * w - cnt - d[h-1][w-1] -1 << endl;
    }
    
    
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<float.h>
#include<algorithm>
struct S{char f[32];int w,s;}F[10];
int main()
{
	int n,w,s,i,a[10],r[10];
	double g,b;
	while(scanf("%d",&n),n)
	{
		b=DBL_MAX;
		for(i=0;i<n;++i)scanf("%s%d%d",F[i].f,&F[i].w,&F[i].s),a[i]=i;
		do
		{
			g=w=0;
			for(i=n-1;i>=0;--i)
			{
				if(F[a[i]].s<w)goto N;
				w+=F[a[i]].w;
				g+=(i+1)*F[a[i]].w;
			}
			if(g<b)b=g,memcpy(r,a,sizeof(a));
N:;
		}while(std::next_permutation(a,a+n));
		for(i=0;i<n;++i)puts(F[r[i]].f);
	}
	return 0;
}

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

using namespace std;

inline int gcd(int a, int b) {
    while (a > 0 && b > 0) {
        int c = a % b;
        a = b, b = c;
    }
    return a + b;
}

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

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    cout << lcm(360, x) / x << '\n';
    return 0;
}


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

using namespace std;

int main(void)
{
    int x,y;
    cin>>x>>y;
    int k = y-2*x;
    int t = y-2*k;
    if( k<0 || k&1 ){
        cout<<"No"<<endl;
    }
    else if( t<0 || t&1){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll i,j,m,n,k;
    ll t;
    string s1,s2;
    cin>>s1>>s2;
    ll ans=0;
    n=s1.size();
    for(i=0;i<n;i++)
    {
        if(s1[i]!=s2[i])
            ans++;
    }
    cout<<ans;
}





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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp(a, b) make_pair(a, b)

const long long MOD = 1000000007;


int main(){
    std::cout<<std::fixed<<std::setprecision(10);
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
    }
    double s = 0;
    rep(i, n){
        s += (1.0/a[i]);
    }

    cout << 1/s << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
class WeightedDisjointSets
{
private:
    using T = int;
    vector<int> parent, rank;
    vector<T> weight;

public:
    WeightedDisjointSets(const int v) : parent(v), rank(v, 0), weight(v, 0) { iota(parent.begin(), parent.end(), 0); }
    bool same(const int a, const int b) { return find(a) == find(b); }
    int find(const int a)
    {
        if (parent[a] == a) { return a; }
        const int r = find(parent[a]);
        weight[a] += weight[parent[a]];
        return parent[a] = find(r);
        // return parent[a] == a ? a : (weight[a] += weight[parent[a]], parent[a] = find(parent[a]));
    }
    T getWeight(const int a) { return find(a), weight[a]; }
    void unite(int a, int b, T d)
    {
        d += getWeight(a) - getWeight(b);
        a = find(a), b = find(b);
        if (a == b) { return; }
        if (rank[a] < rank[b]) { swap(a, b), d = -d; }
        if (rank[a] == rank[b]) { rank[a]++; }
        parent[b] = a, weight[b] = d;
    }
    T diff(const int a, const int b) { return getWeight(b) - getWeight(a); }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int N, M;
        cin >> N >> M;
        if (N == 0 and M == 0) { break; }
        WeightedDisjointSets uf(N);
        for (int i = 0; i < M; i++) {
            char c;
            int a, b;
            cin >> c >> a >> b;
            a--, b--;
            if (c == '!') {
                int c;
                cin >> c;
                uf.unite(a, b, c);
            } else {
                cout << (uf.same(a, b) ? to_string(uf.diff(a, b)) : "UNKNOWN") << "\n";
            }
        }
    }
    return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i = 0; i < N; i++){
        cin >> s.at(i);
    }
    
    int M;
    cin >> M;
    vector<string> t(M);
    for(int i = 0; i < M; i++){
        cin >> t.at(i);
    }

    vector<int> score(N,0);
    int highest = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(s.at(i) == s.at(j)) score.at(i)++;
        }
        for(int j = 0; j < M; j++){
            if(s.at(i) == t.at(j)) score.at(i)--;
        }
        if(highest < score.at(i)) highest = score.at(i);
    }
    cout << max(highest, 0) << endl;

}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

struct bowling
{
	int id,score;
	//bowling(int id,int score):id(id),score(score){};
	bool operator <(const bowling &t)const{
		if(score!=t.score)return score >t.score;
		return id <t.id;
	}
};

int main(){
	int n;
	while(cin>>n,n){
		bowling data[40];
		int pos = 0;
		int N =n;
		cin.ignore();
		while(n--){
			string str;
			getline(cin,str);
			//cout <<"str = "<<str<<endl;
			stringstream ss(str);
			int id;
			ss >>id;
			int a[30]={0};
			for(int j =0;ss>>a[j];){
				j++;
			}
			//cout <<"test"<<endl;
			int scr = 0;
			int x = 0;
			//cout <<"pos = "<<pos<<endl;
			for(int i =1;;i++){
				if(i!=10){
					if(a[x]==10){
						scr +=(10+a[x+1]+a[x+2]);
						x++;
					}
					else if(a[x]+a[x+1]==10){
						scr +=(10+a[x+2]);
						x +=2;
					}else{
						scr +=(a[x]+a[x+1]);
						x +=2;
					}
				}else{
					scr +=(a[x]+a[x+1]+a[x+2]);
					break;
				}
			}
			bowling cs={id,scr};
			data[pos++] =cs;
		}
		sort(data,data+N);
		for(int i =0;i <N;i++){
			cout <<data[i].id<<" "<<data[i].score<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1240
#include<iostream>
using namespace std;
int n,cnt,a[10000];
main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        while(a[i]%2!=1){
            a[i]/=2;
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
while n=gets
 a=n.chomp.to_i
 if a<=40
  a=40
 end
 sum=a
 4.times do
  b=gets.chomp.to_i
  if b<=40
   b=40
  end
  sum+=b
 end
 x=sum/5
 puts x.to_s
end

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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;


const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n'


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

int ans = 0;
bool is_ans_eq_0(int n, string s) {
    rep(i1, n) rep(i2, i1) if (s[i1] == s[i2]) return false;
    return true;
}
void solve(int N, std::string S) {
    if (N < 30 and is_ans_eq_0(N, S)) return;
    int l1 = 0, l2 = 2, len = 1;
    while (l2 + len <= N) {
        while (l2 + len <= N) {
            if (S.substr(l1, len) == S.substr(l2, len)) {
                int m = min(N - l2 + 2, l2 - l1);
                while (S[l1 + len] == S[l2 + len] and (len < m)) len++;
            }
            l2++;
        }
        l1++;
        l2 = l1 + len;
    }
    ans = len;
}

signed main() {
    int N;
    cin >> N;
    std::string S;
    std::cin >> S;

    solve(N, S);

    print(ans);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=2000 +117;
const int MM= +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("019d.in","r",stdin);
	//freopen("019d.cpp.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
char s1[NN]={},s2[NN]={};
bool a[NN],b[NN];
bool chan[NN];
int ans=0;
struct node{
	int l,r;
}t[NN],st[NN];
bool cmp(node a,node b){
	return a.l>b.l||a.l==b.l&&a.r<b.r;
}
void rotate(){
	int tp=b[1];
	for(int i=1;i<n;++i){
		b[i]=b[i+1];
	}
	b[n]=tp;
}
void solve(){
	int lm=n+1,rm=-1;
	for(int i=1;i<=n;++i){
		if(b[i]){
			lm=min(lm,i);
			rm=max(rm,i);
		}
	}
	int lpos=rm-n;
	for(int i=1;i<=n;++i){
		if(b[i]){
			lpos=i;
		}
		t[i].l=i-lpos;
	}
	int rpos=lm+n;
	for(int i=n;i>=1;--i){
		if(b[i])rpos=i;
		t[i].r=rpos-i;
	}
	for(int ro=0;ro<n;++ro){
		int cnt=0;
		for(int i=1;i<=n;++i){
			if(a[i]==b[i]){
				st[i].l=st[i].r=0;
			}
			else{
				st[i].l=t[i].l;
				st[i].r=max(ro,t[i].r);
				++cnt;
			}
		}
		sort(st+1,st+n+1,cmp);
		int  tp=0,rr=ro;
		for(int i=1;i<=n;++i){
			if(st[i].l!=st[i-1].l){
				rr=max(rr,tp);
			}
			tp=st[i].r;
			ans=min(ans,2*st[i].l+2*rr-ro+cnt);
		}

		rotate();
		//cerr<<ans<<endl;
	}
}
void reverse(){
	for(int i=1;i<=n/2;++i){
		swap(a[i],a[n+1-i]);
		swap(b[i],b[n+1-i]);
	}
}
int main(){
	//open();
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	n=strlen(s1+1);
	bool fla,flb;
	for(int i=1;i<=n;++i){
		a[i]=s1[i]-'0';
		b[i]=s2[i]-'0';
		fla|=a[i];
		flb|=b[i];
	}
	ans=3*n;
	if(!flb){
		if(fla){
			printf("-1\n");
		}
		else printf("0\n");
		return 0;
	}
	solve();
	reverse();
	solve();
	
	printf("%d",ans);
	close();
	return 0;
}

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

struct Point{
	double x;
	double y;
};

Point roll(Point div1,Point div2){
	Point tmp_start = { div2.x-div1.x,div2.y-div1.y };
	Point tmp_end = { tmp_start.x*cos(M_PI/3) -tmp_start.y*sin(M_PI/3),
			tmp_start.x*sin(M_PI/3) + tmp_start.y*cos(M_PI/3) };
	Point ret = { tmp_end.x + div1.x,tmp_end.y + div1.y };
	return ret;
}

void outPut(Point point){
	printf("%.8f %.8f\n",point.x,point.y);
}

void calc(Point left,Point right,int count){
	Point div1 = {	(2*left.x + right.x)/3,(2*left.y + right.y)/3 };
	Point div2 = {(2*right.x + left.x)/3,(2*right.y + left.y)/3	};
	Point peek = roll(div1,div2);

	if(count > 1){
		calc(left,div1,count-1);
		calc(div1,peek,count-1);
		calc(peek,div2,count-1);
		calc(div2,right,count-1);
	}else{
		outPut(left);
		outPut(div1);
		outPut(peek);
		outPut(div2);
	}
}

int main(){
	int n;
	Point left = {0,0},right = {100,0};
	scanf("%d",&n);
	if(n == 0){
		outPut(left);
		outPut(right);
	}else{
		calc(left,right,n);
		outPut(right);
	}
}

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

using namespace std;

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

    int l = 0, r = s.size() - 1;
    int ans = 0;
    while(l < r) {
        if(s[l] != s[r]) ans++;
        l++,r--;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpr make_pair
#define mt make_tuple
 
using namespace std;
 
const ll N = 100010;
const ll mod = 1e9 + 7;
ll power(ll x, ll   y, ll p){ ll res = 1; x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;} return res; }
 
ll dp[2][N];
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    ll arr[N][2];
    cin>>n>>w;
    memset(dp, 0, sizeof(dp));
    for(int i=1;i<=n;i++)    cin>>arr[i][0]>>arr[i][1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j >= arr[i][0])
                dp[i%2][j] = max(dp[(i-1)%2][j], arr[i][1] + dp[(i-1)%2][j-arr[i][0]]);
            else    dp[i%2][j] = dp[(i-1)%2][j];
        }
    }
    cout<<dp[n%2][w]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  cout << (long long)floor(n / 500) * 1000 + (long long)floor((n % 500) / 5) * 5 << '\n';
}


Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var N int
  fmt.Scanf("%d\n", &N)
  arr := make([]int, N)
  mp := make(map[int]int)
  for i := 0; i < N; i++ {
    fmt.Scanf("%d", &arr[i])
    mp[arr[i]]++
  }
  Tcnt := 0
  for _, val := range mp{
    Tcnt += val * (val - 1) / 2
  }
  
  for i := 0; i < N; i++ {
    fmt.Println(Tcnt - (mp[arr[i]] - 1))
  }
}

Measured memory_bytes: 16768
//Love and Freedom.
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
#define inf 20021225
#define N 200010
#define mdn 998244353 
using namespace std;
int read()
{
	int s=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return f*s;
}
int f[N][3][3][2],n,ans; char ch[N]; string gg; map<string,bool> vis;
void upd(int &x,int y){x+=x+y>=mdn?y-mdn:y;}
void dfs(string a)
{
	if(vis[a])	return;
	string qwq=a; ans++; vis[a]=1;
	for(int i=0;i<n-1;i++)	if(qwq[i]!=qwq[i+1])
	{
		if((qwq[i]=='a' && qwq[i+1]=='b')||(qwq[i]=='b'&&qwq[i+1]=='a'))
			a[i]=a[i+1]='c',dfs(a),a[i]=qwq[i],a[i+1]=qwq[i+1];
		if((qwq[i]=='a' && qwq[i+1]=='c')||(qwq[i]=='c'&&qwq[i+1]=='a'))
			a[i]=a[i+1]='b',dfs(a),a[i]=qwq[i],a[i+1]=qwq[i+1]; 
		if((qwq[i]=='b' && qwq[i+1]=='c')||(qwq[i]=='c'&&qwq[i+1]=='b'))
			a[i]=a[i+1]='a',dfs(a),a[i]=qwq[i],a[i+1]=qwq[i+1]; 
	}
}
int main()
{
	scanf("%s",ch+1); n=strlen(ch+1);
	if(n<=3)
	{
		for(int i=1;i<=n;i++)	gg=gg+ch[i];
		dfs(gg),printf("%d\n",ans); return 0;
	}
	int flag=0,fs=ch[1]-'a';
	for(int i=2;i<=n;i++)	flag+=(ch[i]==ch[i-1]),(fs+=ch[i]-'a')%=3;
	if(flag==n-1)	return puts("1"),0;
	f[1][0][0][0]=1; f[1][1][1][0]=1; f[1][2][2][0]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<3;j++)	for(int k=0;k<3;k++)
			for(int s=0;s<3;s++)	for(int p=0;p<2;p++)
			{
				int np=(j==k)|p,ns=(k+s)%3;
				upd(f[i][k][ns][np],f[i-1][j][s][p]); 
			}
	}
	int ans=((ll)f[n][0][fs][1]+f[n][1][fs][1]+f[n][2][fs][1]+(!flag))%mdn;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 14464
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    array_result.append(data.split(" "))

    flg = 1

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

a = int(arr_data[0][0][0])
b = int(arr_data[0][0][1])
c = int(arr_data[0][0][2])
d = int(arr_data[0][0][3])

#print(a, b, c, d)

#+++
if a + b + c + d == 7:
  
    print(str(a) + "+" + str(b) + "+" + str(c) + "+" + str(d) + "=7") 

#+-+    
elif a + b - c + d == 7:

    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7") 
  
#++-    
elif a + b + c -d == 7:

    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7") 
  
#+--
elif a + b - c - d == 7:
  
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7") 
  

#-++   
elif a - b + c + d == 7:

    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7") 
  
#-+-
elif a - b + c - d == 7:

    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7") 
  
#--+
elif a - b - c + d == 7:
    
    print(str(a) + "-" + str(b) + "-" + str(c) + "+" + str(d) + "=7") 
  
#---
elif a - b - c - d == 7:

    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7") 
  

Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  
  ll h, w; cin >> h >> w;
  vector<vector<ll>> a(h, vector<ll>(w));
  vector<vector<ll>> b(h, vector<ll>(w));
  vector<vector<ll>> c(h, vector<ll>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      cin >> b[i][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      c[i][j] = abs(a[i][j] - b[i][j]);
    }
  }
  ll max_value = 80 * (h + w);
  vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w,vector<bool>(max_value + 1, false)));
  dp[0][0][c[0][0]] = true;
  rep(i, h) {
    rep(j, w) {
      rep(k, max_value + 1) {
        if (0 <= i + 1 && i + 1 < h && dp[i][j][k]) {
          if (0 <= k + c[i + 1][j] && k + c[i + 1][j] <= max_value) dp[i + 1][j][k + c[i + 1][j]] = true;
          if (0 <= abs(k - c[i + 1][j]) && abs(k - c[i + 1][j]) <= max_value) dp[i + 1][j][abs(k - c[i + 1][j])] = true;
        }
        if (0 <= j + 1 && j + 1 < w && dp[i][j][k]) {
          if (0 <= k + c[i][j + 1] && k + c[i][j + 1] <= max_value) dp[i][j + 1][k + c[i][j + 1]] = true;
          if (0 <= abs(k - c[i][j + 1]) && abs(k - c[i][j + 1]) <= max_value) dp[i][j + 1][abs(k - c[i][j + 1])] = true;
        }
      }
    }
  }
  rep(k, max_value + 1) {
    if (dp[h - 1][w - 1][k]) {
      cout << k << endl;
      exit(0);
    }
  }
}


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

int main() {
  string S;
  cin >> S;
  int A = S[0] - '0', B = S[1] - '0', C = S[2] - '0', D = S[3] - '0';
  if (A + B + C + D == 7)
    cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A - B + C + D == 7)
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A + B - C + D == 7)
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  else if (A + B + C - D == 7)
    cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A - B - C + D == 7)
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  else if (A - B + C - D == 7)
    cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A + B - C - D == 7)
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  else if (A - B - C - D == 7)
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;

  set<ll> s;
  for(ll i=2; i*i<=n; i++){
    ll x=n;
    while(x%i==0)x/=i;
    if((x-1)%i==0){
      if(n%i!=0)
        s.insert((x-1)/i);

      s.insert(i);
    }
  }

  for(ll i=n-1; i<=n; i++){
    if(i==1)
      continue;
    ll x=n;
    while(x%i==0)x/=i;
    if(x%i==1)
      s.insert(i);
  }

  cout<<s.size()<<endl;
}



Measured memory_bytes: 256
n, k, = map(int, input().split())
d = []
a = []
chk = [0] * n
for i in range(k):
    _d = (int)(input())
    d.append(_d)
    _a = list(map(int, input().split()))
    a.append(_a)
    for j in _a:
        if chk[j-1] == 0:
            chk[j-1] = 1

#print("d = {}".format(d))
#print("a = {}".format(a))
#print("chk = {}".format(chk))

ret = 0
for i in chk:
    if i == 0:
        ret += 1

print("{}".format(ret))

Measured memory_bytes: 9192
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#include <numeric>
#include <cctype>
#include <sstream>

using namespace std;

#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define sz(a) (int)(a.size())
#define sqr(a,b) pow(a, b*1.0)
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define ll long long
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vll vector <ll>
#define vpi vector <pii>
#define vpl vector <pll>
#define sc1(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define frw(i, p, n) for(int i = p; i <= n; i++)
#define bck(i, n, p) for(int i = n; i >= p; i--)
#define mem(a) memset(a, 0, sizeof(a))

int main(){  __
	stack<char> st;
	char x;
	while(cin>>x){
		if(st.size()>0){
			char z=st.top();
			if(x=='T' && z=='S'){
				st.pop();
			}else{
				st.push(x);
			}	
		}else{
			st.push(x);
		}
	}

	cout<<st.size();
return 0;
}	
			    

Measured memory_bytes: 512