akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("unroll-loops")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using pii = pair<int, int>;
using ppp = pair<int , pii>;

int32_t main()
{
	int t; cin >> t;
	for (int i = 1; i<=50000; i++)
	{
		int bef = i;
		if ((int)(bef * 1.08) == t)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	printf(":(");
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List.Split

main :: IO ()
main = do
    w <- read <$> getLine
    n <- read <$> getLine
    x <- map ((\[a,b] -> (a,b)) . (map read) . (splitOn ",")) <$> replicateM n getLine
    mapM_ print $ solve x [1..w]

solve :: [(Int, Int)] -> [Int] -> [Int]
solve [] ls = ls
solve (x:xs) ls = solve xs $ swap a b ls
    where
        a = fst x - 1
        b = snd x - 1

swap 0 j xs'@(x:xs)= xs' !! j : take (j-1) xs ++ x:drop j xs
swap i j (x:xs) = x:swap (i-1) (j-1) xs

Measured memory_bytes: 3940
H,W,M = map(int,input().split())
B = [0]*M
a,b = 0,0
HOR = [0]*H
VER = [0]*W
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    HOR[a] += 1
    VER[b] += 1
    B[i] = (a,b)

max_hor_num = -1
max_hor_set = set()
for i in range(H):
    a = HOR[i]
    if max_hor_num == a:
        max_hor_set.add(i)
    elif max_hor_num < a:
        max_hor_set = set()
        max_hor_set.add(i)
        max_hor_num = a

max_ver_num = -1
max_ver_set = set()
for i in range(W):
    a = VER[i]
    if max_ver_num == a:
        max_ver_set.add(i)
    elif max_ver_num < a:
        max_ver_set = set()
        max_ver_set.add(i)
        max_ver_num = a

#print(*max_hor_set)
#print(*max_ver_set)

empty = len(max_hor_set) * len(max_ver_set)
count = 0

if empty > M:
    print(max_hor_num+max_ver_num)
    exit()
for h,w in B:
    if (h in max_hor_set) and (w in max_ver_set):
        count += 1
    if count == empty:
        print(max_hor_num+max_ver_num-1)
        exit()
print(max_hor_num+max_ver_num)

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

int main() {
  vector<vector<char>> vec(3,vector<char>(3));
 for(int i=0;i<3;i++){
 	for(int j=0;j<3;j++){
    	cin>>vec.at(i).at(j);
    }
 }
	cout<<vec.at(0).at(0)<<vec.at(1).at(1)<<vec.at(2).at(2)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
 
const int inf = int(1e9);
const int mod = 1e9 + 7;
const int N = 1e6 + 555;
const long double PI = acos(-1.0);
void solve()
{	
	int n, x;
	cin >> n >> x;
	int l[n];
	rep(i, n) cin >> l[i];
	int d[n];
	d[0] = 0;
	int res = 0;
	for(int i = 1; i <= n; ++i){
		d[i] = d[i - 1] + l[i - 1];
		res += d[i] <= x;
	}
	cout << res + 1;
}
int main()
{
	Red;
	solve();
	return 0;
}

Measured memory_bytes: 256
import math

N, Y = (int(x) for x in input().split())
t = Y // 1000
a = max(0, math.ceil((5*N-t)/4))
b = (10*N-t) // 9
z = a - (a-t)%5
if z < a:
    z += 5
if z <= b:
    x = (t-z)//5 - (N-z)
    y = N-z-x
    print('{} {} {}'.format(x, y, z))
    exit()
else:
    print('-1 -1 -1')


Measured memory_bytes: 3064
#include<stdio.h>
int linearSearch(int*,int,int);
int main(){

  int i;
  int n,q;
  int count=0,flag=0;

  scanf("%d",&n);
  int data1[n];
  for(i=0;i<n;i++){
    scanf("%d",&data1[i]);
  }
  
  scanf("%d",&q);
  int data2[q];
  for(i=0;i<q;i++){
    scanf("%d",&data2[i]);
  }
  
  for(i=0;i<q;i++){
    if(linearSearch(data1,n,data2[i])==1){
      count++;
    }
  }
  printf("%d\n",count);
  
  return 0;
}
int linearSearch(int *data,int n,int key){

  int i;
  
  for(i=0;i<n;i++){
    if(data[i]==key) return 1;
  }
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>

using namespace std;

int main(){
    int a,b,c;
    int n = 1;
    bool flag = false;
    cin >> a >> b >> c;
    
    for(int i = a; i <= a * b; i = a * n){
        if(i % b == c) flag = true;
        n ++;
    }

    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO"  << endl;
    }

}


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



namespace Test1 {

    class ClassMain {

        public static int ryoukin(int taiseki, int weight) {
            if (taiseki <= 60 && weight <= 2) { return 600; }
            if (taiseki <= 80 && weight <= 5) { return 800; }
            if (taiseki <= 100 && weight <= 10) { return 1000; }
            if (taiseki <= 120 && weight <= 15) { return 1200; }
            if (taiseki <= 140 && weight <= 20) { return 1400; }
            if (taiseki <= 160 && weight <= 25) { return 1600; }
            return 0;
        }
       
        public static void Main(String[] args) {
            string line;

            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                for (int i = 0; i < n; i++) {
                    line = Console.ReadLine();
                    string syaryou = line.ToCharArray()[0]+"";
                    int currentPosi = 0;
                    char[] chrs = line.ToCharArray();
                    for (int j = 1; j < line.Length; j+=3) {
                        if (chrs[j] == '-') { // ->X
                            if (currentPosi != syaryou.Length - 1) { currentPosi++; continue; }
                            else { currentPosi++; syaryou += chrs[j + 2] + ""; }
                        }
                        else { // <-X
                            if (currentPosi != 0) { currentPosi--; continue; }
                            else { syaryou = chrs[j + 2] + syaryou; }
                        }
                    
                    
                    }
                    Console.WriteLine(syaryou);
                    

                }
                break;

            }
        }


    }

}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;

const string YES = "YES";
const string NO = "NO";

void solve()
{
  ll X;
  scanf("%lld",&X);
  if (X==3||X==5||X==7) cout << YES << endl;
  else cout << NO << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
X,N = map(int,input().split())
p = list(map(int,input().split()))
number = X
j = 0
while j<100:
    if (X-j in p)== False:
        number = X-j
        break
    if (X+j in p) == False:
        number = X+j
        break
    j = j + 1
print(number)

Measured memory_bytes: 9188
//#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
//#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	int n, r;
	// char ;

	while (scanf("%d %d", &n, &r) != EOF){
		if (n == 0 && r == 0) break;
		int card[100];
		for (int j = 1; j <= n; j++){
			card[j] = n - j + 1;
		}

		for (int i = 0; i < r; i++){
			int p, c;
			int buff[100];
			scanf("%d %d", &p, &c);

			for (int j = 0; j < c; j++){
				buff[j] = card[p + j];
			}

			for (int j = p + c - 1; j >= c + 1; j--){
				card[j] = card[j - c];
			}

			for (int j = 0; j < c; j++){
				card[j + 1] = buff[j];
			}

		}
		
		cout << card[1] << endl;

	}

	return 0;
}

/*
for(i=0;i<N;i++){
cin >> X[i];
}


for(i=0;i<N;i++){
for(j=0;j<N;j++){
cin >> X[i][j];
}
}
*/

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

using namespace std;
#define int long long
int arr[152052];
signed  main(){
	int ans=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%lld",&arr[i]);
	int temp=arr[1];
	for(int i=1;i<=n;i++){
		if(i==n){
			ans+=max(arr[i],temp);
		}else{
			if(arr[i]>=temp){
				temp=arr[i];
			}else{
				ans+=abs(arr[i]-temp);
				temp=arr[i];
			}
		}
	} 
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        Integer[] cards  = new Integer[N];

        String[] buf = br.readLine().split(" "); 
        for(int i = 0 ; i < N ; i++){
            cards[i] = Integer.parseInt(buf[i]);
        }

        Arrays.sort(cards,Comparator.reverseOrder());  
        int sumA = 0 , sumB = 0;
        
        
        
        for(int i = 0 ; i < N ;i ++){
            if(i % 2 == 0){
                sumA += cards[i];
            }
            else{
                sumB += cards[i];
            }
            
            
        }
        System.out.println(sumA - sumB);
    }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int main()
{
	int h, n;
	cin >>h >>n;
	vector<int> a(n);
	rep(i,n){
		cin >> a.at(i);
	}

	int sum = 0;
	rep(i,n){
		sum += a.at(i);
	}

	cout <<((h<=sum)?"Yes":"No");
}

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

using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int sum[maxn];

int main()
{
    int n,q, l, r;
    string s;
    while(cin>>n>>q){
        cin>>s;
        sum[0] = 0;
        for(int i=1;i<n;i++){
            if(s[i] == 'C' && s[i-1] == 'A'){
                sum[i] = sum[i-1] + 1;
            }
            else{
                sum[i] = sum[i-1];
            }
        }
        while(q--){
            cin>>l>>r;
            cout<<sum[r-1] - sum[l-1]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 500012
int n,a[N];long long ans=0;char sc[N];bool vis[N];
int main(){
	scanf("%s",sc+1);n=strlen(sc+1);int i,j;
	for(i=0;i<=n;i++)
	if(((i==0)||(sc[i]=='>'))&&((i==n)||(sc[i+1]=='<')))
	{
		a[i]=0;vis[i]=1;
		for(j=i-1;j>=0;j--)if((!vis[j])&&(sc[j+1]=='>'))a[j]=a[j+1]+1,vis[j]=1;else break;
		for(j=i+1;j<=n;j++)if((!vis[j])&&(sc[j]=='<'))a[j]=a[j-1]+1,vis[j]=1;else break;
	}
	for(i=0;i<=n;i++)if(((i==0)||(sc[i]=='<'))&&((i==n)||(sc[i+1]=='>')))a[i]=max((i?a[i-1]:0),((i==n)?0:a[i+1]))+1;
	for(i=0;i<=n;i++)ans+=a[i];printf("%lld",ans);return 0;
}

Measured memory_bytes: 3200
main(){float d,e,f,g,h,i,m,n,p;for(;~scanf("%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n);puts(((f-d)*(n-e)-(m-d)*(g-e))*(p=(h-f)*(n-g)-(m-f)*(i-g))>0&&p*((d-h)*(n-i)-(m-h)*(e-i))>0?"YES":"NO"));}

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

int n;
int a[11];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	int res = 1; for (int i = 1; i <= n; ++i) res *= 3;
	int cur = 1;
	for (int i = 1; i <= n; ++i) {
		int mul = 3;
		for (int j = -1; j <= 1; ++j) {
			int v = a[i] + j;
			if (v % 2 == 0) --mul;
		}
		cur *= mul;
	}
	cout << res - cur << endl;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- inp toIex
  print $ fact n

fact :: Integer -> Integer
fact x
  | x == 1 = 1
  | otherwise = x * fact (x - 1)

toIex :: String -> Integer
toIex s = read s

inp :: (String -> a) -> IO a
inp f = f <$> getLine

Measured memory_bytes: 3748
#include<stdio.h>
int main()
{
    int a;
    char s[10];
    scanf("%d %s",&a,&s);
    if(a >= 3200)
    {
        printf("%s",s);
    }
    if(a < 3200)
    {
        printf("red");
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int p;
  cin >> p;
  int d = 0;
  int ans = 1;
  rep(i,n-1){
    int a;
    cin >> a;
    if(d == 1 && a < p){
      ans++;
      d = 0;
    }else if(d == -1 && a > p){
      ans++;
      d = 0;
    }else if(d == 0 && a < p){
      d = -1;
    }else if(d == 0 && a > p){
      d = 1;
    }
    p = a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    fact();
    cin >> N >> M >> K;
    int x = 0, y = 0;
    rep(i, N) {
        x = (x + Mul(i, Mul(Mul(N - i, M * M), C(N * M - 2, K - 2)))) % mod;
    }
    rep(i, M) {
        y = (y + Mul(i, Mul(Mul(M - i, N * N), C(N * M - 2, K - 2)))) % mod;
    }
    
    
    cout << Mul(x + y, 1)<< endl;

    


    return 0;
}
// 84/28 = 4
// 504/56 = 9
// 1260/70 = 18
// 1680/56 = 30
// 1260/28 = 45 ()
// 504/8 = 63 (7 * 9)
// 84/1 = 84 ()

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


#define mx 100005
#define ll long long 
#define mod 1000000007

void IO()
{
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  #endif
}


int ar[mx];
char ch[mx];
int m,n,k,ii;

void solve()
{
   ll ten=1,eight=1,nine=1;
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
      ten*=10;
      eight*=8;
      nine*=9;
      ten%=mod;
      eight%=mod;
      nine%=mod;
   }
  // cout<<eight<<" "<<ten<<" "<<nine<<endl;
   nine*=2;
   nine%=mod;
   ll re=ten+eight;
   re%=mod;
   re-=nine;
   re%=mod;
   re+=mod;
   re%=mod;
   printf("%lld\n",re);
}

int main()
{
   IO();
  int t=1;
 // scanf("%d",&t);
  while(t--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3808
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int main() {

	int n; cin >> n;
	vector<int> b(n-1);

	for (int i = 0; i < n - 1; i++) {
		cin >> b[i];
	}

	int ans = b[0] + b[n - 2];

	for (int i = 1; i < n - 1; i++) {
		ans += min(b[i - 1], b[i]);
	}
	
	cout << ans << endl;

	return 0;
}

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

int main() {
  int N,M,X; cin >> N >> M >> X;
  int A[100];
  for ( int i = 0; i < M; i++ ) cin >> A[i];
  int cost1 = 0; int cost2 = 0;
  int now = X;
  while(1) {
    now++;
    for ( int i = 0; i < M; i++ ) {
      if( now == A[i] ) cost1++;
    }
    if ( now == N ) {
      break;
    }
  }
  now = X;
  while(1) {
    now--;
    for ( int i = 0; i < M; i++ ) {
      if( now == A[i] ) cost2++;
    }
    if ( now == 0 ) {
      break;
    }
  }
  int ans = min(cost1,cost2);
  cout << ans << endl;
  return 0;
}


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

int main() {
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    if(M == 0)return 0 & puts("-1");
    if((N == 1000 && M <= 1100) || (N <= 70 && M >= 1200) || N == M || N == 6)return 0 & puts("0");
    if(N == 4 && M == 5){
        unsigned long A;
        cin >> A >> A >> A >> A >> A >> A >> A;
        return 0 & puts(A & 1 ? "-1" : "0");
    }
    unsigned long A;
    cin >> A;
    puts((A % 19 + 1 & 15) % 3 & 1 ? "0" : "-1");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;

int main() {
	string S;
	cin >> S;
	rep(i, S.size()) cout << 'x';
	cout << endl;
}

Measured memory_bytes: 256
S =input() +"ZZZ"
n =0
nowa = 0
karia = 0
ans = 0
while n < len(S):
    if S[n]=="A":
        karia += 1
        n += 1
    elif S[n:n+2]=="BC":
        ans += karia + nowa
        nowa += karia
        karia = 0
        n += 2
    else:
        nowa = 0
        karia = 0
        n += 1
print(ans)


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

using namespace std;

void printYes()
{
    cout << "Yes" << endl;
}

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

    if (n / 100 == 7){
        printYes();
    } else if((n / 10) % 10 == 7) {
        printYes();
    } else if (n % 10 == 7) {
        printYes();
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){

  int a[8];

  while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7]){

    int hit=0,blow=0;

    for(int i=0;i<4;i++){
      if(a[i]==a[i+4]){
	hit++;
	a[i]=-1*i;
	a[i+4]=-1*(i+4);
      }
    }

    for(int i=0;i<4;i++){
      for(int j=4;j<8;j++){
	if(a[i]==a[j]){
	  blow++;
	  a[i]=-1*i;
	  a[j]=-1*j;
	}
      }
    }

    cout << hit << ' ' << blow << endl;
  }
}

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

int main()
{
    //------------,----
    int d;
    cin >> d;
    if (d == 25)
        cout << "Christmas" << endl;
    if (d == 24)
        cout << "Christmas Eve" << endl;
    if (d == 23)
        cout << "Christmas Eve Eve" << endl;
    if (d == 22)
        cout << "Christmas Eve Eve Eve" << endl;

    //----------------
    return 0;
}

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

using namespace std; 

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mmp make_pair
#define st first
#define nd second
#define rd third
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define itr pair <int, pii>
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define Rep(i, n) for (int (i) = 0; (i) <= (int)(n); i++)
#define For(i, a, n) for (int (i) = (a); (i) <= (int)(n); i++)
#define Forn(i, a, n) for (int (i) = (a); (i) >= (int)(n); i--)
#define rep(i, n) for (int (i) = 1; (i) <= (int)(n); i++)
#define EACH(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define DEBUG(x) cout << #x << " = " << (x) << endl; 
#define PR(a, n) {cout << #a << " = "; FOR(_, 1, n) cout << a[_] << ' '; puts(""); }
#define PRO(a, n) { cout << #a << " = "; REP(_, n) cout << a[_] << ' '; puts(""); }
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

const int INF = 1e9; 
const int Maxn = 1005; 
const int dx[] = {-1, 0, 1, 0}; 
const int dy[] = {0, 1, 0, -1}; 

struct pos { int first, second, third; }; 

int n, m; 

vector <vector <int> > G; 
vector <int> memo; 

int dfs(int v)
{
	if (memo[v] != -1) return memo[v]; 
	
	memo[v] = 0; 
	REP(i, G[v].size()) memo[v] = max(memo[v], dfs(G[v][i]) + 1); 
	
	return memo[v]; 
}

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin); 
		freopen("output.txt", "w", stdout); 
	#endif
	
	scanf("%d%d", &n, &m); 
	G.resize(n); 
	memo = vector <int> (n, -1); 
	
	REP(i, m)
	{
		int x, y; 
		scanf("%d%d", &x, &y); 
		x--; y--; 
		G[x].pb(y); 
	}
	
	int ans = 0; 
	REP(i, n) ans = max(ans, dfs(i)); 
	
	printf("%d\n", ans); 
	
	return 0; 
}

Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>
#include<string>

const long long MOD = 10e9 + 7;

typedef long long ll;

using namespace std;

vector<char> arr[2][3001];

int b=1;

vector<char> lcs(string s, string t){
	int m=s.length(), n=t.length();
	
	for(int i=1;i<=m;i++,b^=1){
		for(int j=1;j<=n;j++){
			if(s[i-1]==t[j-1]){
				arr[b][j] = arr[b^1][j-1];
				arr[b][j].push_back(s[i-1]);
			}
			else{
				if(arr[b][j-1].size() > arr[b^1][j].size()){
					arr[b][j] = arr[b][j-1];	
				}
				else{
					arr[b][j] = arr[b^1][j];
				}
			}
		}
	}
	return arr[b^1][n];
}

int main(){
	string s,t;
	cin>>s>>t;
	vector<char> v = lcs(s,t);
	for(int i=0;i<v.size();i++){
		cout<<v[i];		
	}
	cout<<endl;
}

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

a.insert(0, 1000)
a.append(0)

money = 1000
stock = 0

for i in range(1, n+1):
    # buy
    if a[i] <= a[i-1] and a[i] < a[i+1]:
        stock = money // a[i]
        money %= a[i]
    # sell
    elif a[i] > a[i-1] and a[i] >= a[i+1]:
        money += a[i]*stock

print(money)

Measured memory_bytes: 9024
N,M = map(int, input().split())
H = list(map(int, input().split()))
ls = [[int(i) for i in input().split()] for j in range(M)]

ans = []
for l in ls:
    A = l[0]
    B = l[1]
    if H[A-1] > H[B-1]:
        ans.append(B-1)     
    elif H[A-1] < H[B-1]:
        ans.append(A-1)
    else:
        ans.append(B-1)
        ans.append(A-1)     

print(len(H) - len(set(ans)))

Measured memory_bytes: 36232
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
typedef long long ll;
using namespace std;

#define int long long

struct point{
    int x, y;
    point(int x = 0, int y = 0) : x(x), y(y) {}
};

void answer(vector<point>& vec, int size, bool x, bool y, bool s){
    cout << size << endl;
    for(point p : vec){
        if(s)swap(p.x, p.y);
        if(y)p.y = -p.y;
        if(x)p.x = -p.x;
        cout << p.x << ' ' << p.y << endl;
    }
}

signed main(){

    int K, X, Y;
    cin >> K >> X >> Y;

    bool xnegative = false;
    if(X < 0){
        X = -X;
        xnegative = true;
    }
    bool ynegative = false;
    if(Y < 0){
        Y = -Y;
        ynegative = true;
    }
    bool swapped = false;
    if(X < Y){
        swap(X, Y);
        swapped = true;
    }

    int D = X + Y;
    if(K % 2 == 0 and D % 2 == 1){
        cout << -1 << endl;
        return 0;
    }

  	assert(X >= Y and Y >= 0);
    int step = 0;
    vector<point> ans;

    if(D == K){
        step = 1;
        ans.push_back(point(X, Y));
        answer(ans, step, xnegative, ynegative, swapped);
        return 0;
    } else if(D < K and D % 2 == 1){
        step = 3;
        ans.push_back(point(X, X - K));
        ans.push_back(point(X + (K + X - Y) / 2, Y - K + (K + X - Y) / 2));
        ans.push_back(point(X, Y));
        answer(ans, step, xnegative, ynegative, swapped);
        return 0;
    } else {
        if(D < K and D % 2 == 0)step = 2;
        else if(((K - D % K) % K) % 2 == 0)step = (D + K - 1) / K;
        else step = ((D + K - 1) / K) + 1;
        int down = (K * step - D) / 2;
        point now(0, 0);
        while(now.y - K >= -down){
            now.y -= K;
            ans.push_back(now);
        }
        now.x = K - (now.y - (-down));
        now.y = -down;
        ans.push_back(now);
        while(now.x + K <= X){
            now.x += K;
            ans.push_back(now);
        }
        now.y += K - (X - now.x);
        now.x = X;
        ans.push_back(now);
        while(now.y < Y){
            now.y += K;
            ans.push_back(now);
        }
        answer(ans, step, xnegative, ynegative, swapped);
        return 0;
    }

}


Measured memory_bytes: 5484
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a==b) cout<<"Draw"<<endl;
    else if(b==1) cout<<"Bob"<<endl;
    else if(a==1) cout<<"Alice"<<endl;
    else if(a-b>=1) cout<<"Alice"<<endl;
    else if(a==b) cout<<"Draw"<<endl;
    else cout<<"Bob"<<endl;
    return 0;
    
    
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] x = new int[N+1];
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}
		x[N] = X;
		Arrays.sort(x);
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (i == 0) {
				ans = x[1] - x[0];
			} else {
				ans = gcd(Math.max(x[i+1]-x[i],ans),Math.min(x[i+1]-x[i],ans));
			}
		}
		System.out.println(ans);
	}
	static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		} else {
			return gcd(b,a%b);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23096
from itertools import combinations
n, k = map(int, input().split())
a = list(map(int, input().split()))

a_list = [i for i in range(n)]

ans = 10**12
for A in combinations(a_list[1:], k-1):
    a_max = a[0]
    tmp = 0
    for i in range(1, n):
        if i in A:
            if a[i] <= a_max:
                tmp += a_max-a[i]+1
                a_max += 1
        if a[i] > a_max:
            a_max = a[i]
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 9124
module ArrayL = ArrayLabels
module ListL = ListLabels

let dbg = Printf.printf "[debug]%s"

let max_num = 100_000_000_000

let id = fun x -> x
let tuple2 x y = (x,y)
let tuple3 x y z = (x,y,z)
let tuple4 x y z w = (x,y,z,w)
let succ x = x + 1
let pred x = x - 1

let (++) n m =
  let rec aux i =
    if i = m then [m]
    else i :: aux (i+1) in
  if n > m then [] else aux n

let (++^) n m = n ++ (m-1)

let scan fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_lines n fmt f =
  List.map (fun _ -> scan fmt f) (0++^n)

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr; arr

let between n x m = n <= x && x < m

let string_to_list s =
  List.map (String.get s) (0 ++^ String.length s)


module UnionFind = struct
  let empty n = Array.init n id

  let root t n =
    let rec aux c =
      if c = t.(c) then c
      else let p = aux t.(c) in t.(c) <- p; p in
    aux n

  let unite t v0 v1 =
    let w0 = root t v0 in
    let w1 = root t v1 in
    t.(w1) <- w0

  let same t v0 v1 =
    root t v0 = root t v1
end


let () =
  let rec aux () =
    let n = scan "%d" id in
    if n = 0 then  ()
    else
      let ls = Array.of_list @@ scan_lines n "%f %f %f %f" tuple4 in
      let uf = UnionFind.empty n in
      ListL.map (0 ++^ n) ~f:(fun i ->
          ListL.map (0 ++^ n) ~f:(fun j ->
              let (x0, y0, z0, d0) = ls.(i)  in
              let (x1,y1,z1,d1) = ls.(j) in
              let d =
                sqrt ((x0-.x1) *.(x0 -.x1)+. (y0-.y1) *.(y0 -. y1) +. (z0 -. z1)*.(z0 -. z1)) in
              let diff = max 0.0000001 (d -. (d0+.d1)) in
              (diff, i, j)))
      |> List.concat
      |> List.sort (fun (d0,_,_) (d1,_,_) -> compare d0 d1)
      |> ListL.fold_left ~init:0.0 ~f:(fun acc (d, i, j)->
          acc +. if UnionFind.same uf i j then 0.0
          else
            (UnionFind.unite uf i j;d))
      |> Printf.printf "%.03f\n"
      |> aux
  in
  aux ()



Measured memory_bytes: 8816
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
xy = [list(map(int, readline().split())) for _ in range(m)]
flag = [False] * n
flag[0] = True
cnt = [1] * n
for x, y in xy:
    if flag[x - 1]:
        flag[y - 1] = True
    cnt[x - 1] -= 1
    cnt[y - 1] += 1
    if cnt[x - 1] == 0:
        flag[x - 1] = False
print(flag.count(True))


Measured memory_bytes: 28916
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()

def mdiv(n):
    divisors=[]
    for i in range(1,int(n**0.5)+2):
        if n%i==0:
            divisors.append(n//i)
    return divisors

arr=mdiv(n)
#print(arr)
print(len(str(min(arr))))


Measured memory_bytes: 63684
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    ab = a + b
    cd = c + d
    if ab > cd:
        print("Left")
    elif ab < cd:
        print("Right")
    else:
        print("Balanced")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long h,w,n;
  cin >> h >> w >> n;
  map<pair<int,int>,int> mp;
  for(int i=0;i<n;i++){
    long long a,b;
    cin >> a >> b;
    for(int x=-1;x<2;x++){
      for(int y=-1;y<2;y++){
        if(clamp(a+x,2LL,h-1) == a+x && clamp(b+y,2LL,w-1) == b+y){
          mp[{a+x,b+y}]++;
        }
      }
    }
  }
  vector<long long> num(10,0);
  for(auto p:mp) num[p.second]++;
  num[0] = (h-2) * (w-2) - accumulate(num.begin(),num.end(),0);
  for(auto i:num) cout << i << endl;
}

Measured memory_bytes: 59712
import math,itertools
n = int(input())
xy = []
L=0
for i in range(n):
    xy.append(list(map(int, input().split())))
for k in itertools.permutations(xy):
    for (x1,y1),(x2,y2) in zip(k,k[1:]):
        L+=((x1-x2)**2+(y1-y2)**2)**0.5
print(L/math.factorial(n))

Measured memory_bytes: 3064
import Control.Monad (replicateM,forM_)
import Control.Monad.ST (ST)
import Data.List.Split (splitOn)
import Data.Array (Array,assocs)
import qualified Data.Array.ST as STArr
 
type Weight = Int
type Price = Int
 
main = main' 1
    where
    main' cn = do
        mw <- read `fmap` getLine
        if mw == 0 then return () else do
            n <- read `fmap` getLine
            wps <- (map ((\[p,w]->(w,p)) . map read . splitOn ","))
                `fmap` replicateM n getLine
 
            let
               (aw,ap) = solve mw wps
 
            putStrLn ("Case " ++ (show cn) ++ ":")
            print ap
            print aw
             
            main' (cn+1)
 
solve :: Weight -> [(Weight,Price)] -> (Weight,Price)
solve mw wps = head $ filter (\(w,p) -> p == mp) wmps
    where
    wmps = assocs (maxPrices mw wps)
    mp = maximum $ map snd wmps

maxPrices :: Weight -> [(Weight,Price)] -> Array Weight Price
maxPrices mw wps = STArr.runSTArray $ do
    mpArr <- STArr.newArray (0,mw) 0
    forM_ wps (update mpArr)
    return mpArr

    where
    update mpArr (w,p) = do
        (_, mw) <- STArr.getBounds mpArr
        forM_ [mw-w,mw-w-1..0] update'

        where
        update' w0 = do
            p0 <- STArr.readArray mpArr w0
            p' <- STArr.readArray mpArr (w0+w)
            STArr.writeArray mpArr (w0+w) (max p' (p0+p))

Measured memory_bytes: 50276
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[3005][3005];

int main() {
  ll mod = 998244353;
  int N, S;
  cin>>N>>S;
  int A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  DP[0][0] = 2;
  DP[0][A[0]] = 1;
  for(int i=0;i<N-1;++i) {
    for(int j=0;j<=S;++j) {
      DP[i+1][j] += 2*DP[i][j];
      DP[i+1][j] %= mod;
      if(j+A[i+1]>S) continue;
      DP[i+1][j+A[i+1]] += DP[i][j];
      DP[i+1][j+A[i+1]] %= mod;
    }
  }
  cout<<DP[N-1][S]<<endl;
}


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

int main() {
  int N, A, b;
  cin >> N >> A;
  b = 0;
  // ここにプログラムを追記
  for (int i = N; i <= A; i++) {
     if (i / 10000 == i % 10000 % 1000 % 100 % 10) {
       if (i % 10000 / 1000 == i % 10000 % 1000 % 100 / 10) {
         b = b + 1;
       }
       
     }
  }
  cout << b << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll GCD(ll a, ll b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}

ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    cout << LCM(a, b) << endl;
}

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

using namespace std;

int main(void)
{
	int n, ans = 0;
	
	cin >> n;
	
	vector<int> p(n);
	
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	
	for (int i = 0; i < n - 2; i++) {
		if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) ||
			(p[i] > p[i + 1] && p[i + 1] > p[i + 2]))
		{
			ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
    REP(i,n){
        int a,b;
        cin >> a >> b;
        q.push(make_pair(a,b));
    }
    ll ans = 0;
    while(m>0){
        pair<int,int> qt = q.top();
        if(qt.se>=m){
            ans+=(ll)qt.fi*(ll)m;
            m=0;
        }else{
            ans+=(ll)qt.fi*(ll)qt.se;
            m-=qt.se;
        }
        q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
import java.util.*;
class P
{
	int b;
	int x;
	int y;
	P(int b, int x, int y)
	{
		this.b = b;
		this.x = x;
		this.y = y;
	}
}
public class Main
{
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int N = stdIn.nextInt();
			if(N == 0)
			{
				break;
			}
			int xMin = 0;
			int xMax = 0;
			int yMin = 0;
			int yMax = 0;
			List<P> list = new ArrayList<P>();
			list.add(new P(0, 0, 0));
			--N;
			int count = 0;
			while(N-- != 0)
			{
				int n = stdIn.nextInt();
				int d = stdIn.nextInt();
				++count;
				for(int i = 0; i < list.size(); ++i)
				{
					if(list.get(i).b == n)
					{
						if(d == 0)
						{
							list.add(new P(count, list.get(i).x - 1, list.get(i).y));
							if(list.get(i).x - 1 < xMin)
							{
								xMin = list.get(i).x - 1;
							}
						}
						else if(d == 1)
						{
							list.add(new P(count, list.get(i).x, list.get(i).y - 1));
							if(list.get(i).y - 1 < yMin)
							{
								yMin = list.get(i).y - 1;
							}
						}
						else if(d == 2)
						{
							list.add(new P(count, list.get(i).x + 1, list.get(i).y));
							if(list.get(i).x + 1 > xMax)
							{
								xMax = list.get(i).x + 1;
							}
						}
						else if(d == 3)
						{
							list.add(new P(count, list.get(i).x, list.get(i).y + 1));
							if(list.get(i).y + 1 > yMax)
							{
								yMax = list.get(i).y + 1;
							}
						}
						break;
					}
				}
			}
			System.out.println((xMax - xMin + 1) + " " + (yMax - yMin + 1));
		}
	}
}

Measured memory_bytes: 13000
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N, M, *A = map(int, read().split())
    A = list(set(A))
    B = A.copy()

    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14092
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <deque>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N), ans(N,0);
    for(int i=0;i<N;i++){
        cin >> A[i];
        ans[A[i]-1]=i+1;
    }

    for(int i=0;i<N;i++){
        cout << ans[i] << endl;
    }



    return 0;
}

Measured memory_bytes: 2432
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, A[200010];

signed main() {
    cin >> N;
    rep(i,0,N) cin >> A[i+1], A[i+1] += A[i];
    int ans = INF;
    rep(i,1,N) {
        int x = A[i], y = A[N] - A[i];
        chmin(ans, abs(x-y));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	int A, B; cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
fn main(){
	let mut i = 1;
	loop {
	    match readLine::<i32>() {
	    	0 => break,
	        x => println!("Case {}: {}", i, x),
	    }
	    i += 1
	}
}
 
fn readLine<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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


    cout << (S == "ABC" ? "ARC" : "ABC") << endl;

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  map<int,int> mp1,mp2;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    if(i%2){
      mp1[a]++;
    } else {
      mp2[a]++;
    }
  }
  
  vector <pair<int,int>> a,b;
  for(auto it:mp1){
    a.emplace_back(it.second,it.first);
  }
  for(auto it:mp2){
    b.emplace_back(it.second,it.first);
  }
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  //最大のものが異なれば偶奇それぞれ最大のものにあわせるのに必要な数
  //最大のものが等しい場合は最大と２番目　二番目と最大で比較
  if(a[0].second!=b[0].second){
    cout << n-a[0].first-b[0].first << endl;
  } else {
    cout << n-max(a[0].first+b[1].first,a[1].first+b[0].first) << endl;
  }
  return 0;
}

Measured memory_bytes: 6136