akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main{

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        int[][] bingo = new int[3][3];
        // bingoの入力値をセット
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                bingo[i][j] = Integer.parseInt(scanner.next());
            }
        }
        // 選んだ数
        int count = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        // 選んだ数の内容を取得
        for(int i=0; i<count; i++){
            list.add(scanner.nextInt());
        }
        scanner.close();
        // bingoから探す
        int[][] result = new int[3][3];
        int count0 = 0;
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(list.contains(bingo[i][j])){
                    result[i][j] = 1;
                    count0 += 1;
                }else{
                    result[i][j] = 0;
                }
            }
        }
        if(count0 < 3){
            System.out.println("No");
            return;
        }
        //縦チェック
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        
        if(result[0][2]==1 && result[1][1]==1 && result[2][0]==1){
            System.out.println("Yes");
            return;
        }

        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(result[i][j]==1){
                    count1 += 1;
                }
                if(count1==3){
                    System.out.println("Yes");
                    return;
                }
                if(result[j][i]==1){
                    count2 += 1;
                }
                if(count2==3){
                    System.out.println("Yes");
                    return;
                }
                
            }
            if(result[i][i]==1){
                count3 += 1;
            }
            if(count3==3){
                System.out.println("Yes");
                return;
            }
            count1 = 0;
            count2 = 0;
        }
       System.out.println("No");
    }
}

Measured memory_bytes: 21844
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 # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    n = int(input())
    A = readInts()
    B = readInts()
    ma = -1
    for i in range(n): # 何番目でswitch
        ma = max(ma,sum(A[:i+1]) + sum(B[i:]))
    print(ma)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5276
#include <bits/stdc++.h>
 
 
using namespace std;
typedef long long ll;
 
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
int T;
const int maxN = 1e6+8;
const ll INF = 1e15+7;


int n;
int m;

int main() {
	int m,d;
	scanf("%d %d",&m,&d); 
	int ans = 0;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=d;j++)
		{
			int x = j%10;
			int y = j/10;
			if(x>=2 && y >= 2 && x*y == i)
			{
				ans++;
			}
		}
	}
	cout<<ans<<endl;
    return 0;
}

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



int main(void){
    int n;
    cin >> n;
    vector<int> a;
    rep(i,n){
        int x;
        cin >> x;
        if(x%2==0){
            a.push_back(x);
        }
    }
    int ans =0;
    rep(i,a.size()){
        while(a[i]%2==0){
            a[i] = a[i]/2;
            ans++;
        }
    }
    cout << ans <<endl;
    
    
    
    return 0;
}






























































Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int a = B - A;
		if(a <= 0) {
			System.out.println("delicious");
		} else if(a <= x) {
			System.out.println("safe");
		} else {
			System.out.println("dangerous");
		}
	}
}

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

int main(){
    int n,i;
    long long k;
    cin >> n >> k;
    vector<vector<int>> ab(n,vector<int>(2));
    for(i=0;i<n;i++){
        cin >> ab.at(i).at(0) >> ab.at(i).at(1);
    }
    sort(ab.begin(),ab.end());i=0;
    while(true){
        k-=ab.at(i).at(1);
        if(k<=0){cout << ab.at(i).at(0) << endl;break;}
        i++;
    }
    return 0;
}

Measured memory_bytes: 8804
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define bod 100000007
/****************************/
using namespace std;
int n;
int a[100010];
int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];
	}
	a[n]=0;
	ll ans=0;
	rep3(i,1,n)
	{
		if(a[i-1]>=2)
		{
			ans+=a[i-1]/2;
			a[i-1]%=2;
		}
		int tem=min(a[i-1],a[i]);
		ans+=tem;
		a[i-1]-=tem;
		a[i]-=tem;
	}
	ans+=a[n-1]/2;
	cout<<ans;
	return 0;
}

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

int main(void)
{
	int X = 0;
	int A = 0;
	int B = 0;

	scanf("%d", &X);
	scanf("%d", &A);
	scanf("%d", &B);

	if (1 > A || 1000 < B || X > 10000) {
		return -1;
	}

	if (X < (A + B)) {
		return -1;
	}

	int result = X - A;
	int donuts = result / B;

	result -= (B * donuts);

	printf("%d", result);
    return 0;
}


Measured memory_bytes: 128
using Yorukatsu055.Questions;
using Yorukatsu055.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu055.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/abc103/tasks/abc103_c
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var a = inputStream.ReadIntArray();

            yield return a.Sum(i => i - 1);
        }
    }
}


namespace Yorukatsu055
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu055.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu055.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

int N, W;
long long dp[100005];

int main() {
    cin >> N >> W;

    int w, v;
    for (int i = 1; i <= N; ++i) {
        cin >> w >> v;
        for (int x = W; x >= 0; --x) {
            if (x - w >= 0)
                dp[x] = max(dp[x], dp[x - w] + v);
        }
    }

    long long ans = 0LL;
    for (int x = 0; x <= W; ++x) {
        ans = max(ans, dp[x]);
    }
    cout << ans << endl;

}

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

int main() {
    ll n, m, l; cin >> n >> m >> l;
    vector<vector<ll>> a(n, vector<ll>(m));
    vector<vector<ll>> b(m, vector<ll>(l));

    rep(i, n) {
        rep(j, m) {
            cin >> a.at(i).at(j);
        }
    }
    rep(i, m) {
        rep(j, l) {
            cin >> b.at(i).at(j);
        }
    }
    vector<vector<ll>> ans(n, vector<ll>(l));
    rep(i, n) {
        rep(j, l) {
            rep(k, m) {
                ans.at(i).at(j) += a.at(i).at(k) * b.at(k).at(j);
            }
        }
    }
    rep(i, n) {
        rep(j, l) {
            cout << ans.at(i).at(j);
            if (j != l-1)
                cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3264
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ps, ms, zs;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        (a > 0 ? ps : a == 0 ? zs : ms).push_back(a);
    }

    stringstream ss;
    int num;
    while(ps.size() < 2 && zs.size()){
        ps.push_back(zs.back());
        zs.pop_back();
    }
    ms.insert(ms.end(), zs.begin(), zs.end());
    if(ps.size() >= 2){
        if(ms.empty()){
            sort(ps.rbegin(), ps.rend());
            ms.push_back(ps.back());
            ps.pop_back();
        }
        if(ps.size() == 1){
            ss << ps.back() << ' ' << ms.back() << '\n';
            num = ps.back() - ms.back();
            ps.pop_back();
            ms.pop_back();
        }else{
            ss << ms.back() << ' ' << ps.back() << '\n';
            num = ms.back() - ps.back();
            ps.pop_back();
            ms.pop_back();
            while(ps.size() != 1){
                ss << num << ' ' << ps.back() << '\n';
                num -= ps.back();
                ps.pop_back();
            }
            ss << ps.back() << ' ' << num << '\n';
            num = ps.back() - num;
            ps.pop_back();
        }
    }else if(ps.size() == 1){
        ss << ps.back() << ' ' << ms.back() << '\n';
        num = ps.back() - ms.back();
        ps.pop_back();
        ms.pop_back();
    }else if(ps.empty()){
        sort(ms.begin(), ms.end());
        ss << ms.back() << ' ' << ms[n - 2] << '\n';
        num = ms.back() - ms[n - 2];
        ms.pop_back();
        ms.pop_back();
    }
    while(ms.size()){
        ss << num << ' ' << ms.back() << '\n';
        num -= ms.back();
        ms.pop_back();
    }
    cout << num << '\n';
    cout << ss.str() << '\n';
}


Measured memory_bytes: 7404
package main

import "fmt"

func main() {
	var n int
	ans := 1
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
		if a[i] == 0 {
			fmt.Println(0)
			return
		}
	}
	for _, v := range a {
		ans *= v
		if ans > 1000000000000000000 || ans < v {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6304
#include <cstdio>
#include <string>
#include <list>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    
    list<int> l;
    while(n--){
        char cmdChar[64];
        scanf("%s", cmdChar);
        string command(cmdChar);
        if(command == "deleteFirst"){
            l.pop_front();
        }else if(command == "deleteLast"){
            l.pop_back();
        }else{
            int i;
            scanf("%d", &i);
            if(command == "insert"){
                l.push_front(i);
            }else if(command == "delete"){
                list<int>::iterator it = l.begin();
                while(it != l.end()){
                    if(i == *it){
                        l.erase(it);
                        break;
                    }
                    it++;
                }
            }
        }
    }
    list<int>::iterator it = l.begin();
    while(it != l.end()){
        printf("%d", *it);
        it++;
        printf("%c", it == l.end() ? '\n' : ' ');
    }
    return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int n; 
int main(void) 
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n; 
	double ret = 0.0; 
	double ev = n/2; 
	double od = n-ev; 
	ret = od/n;
	cout << ret << '\n';
	return false; 
}


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

using namespace std;

int main()
{

    int n, m;
    cin >> n >> m;
    int tmp1 = 1;
    int tmp2 = 1;
    int ans = 0;

    ans = n * (n - 1) / 2 + m * (m - 1) / 2;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
//ll arr[1000002];
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/

int main()
{
  ll a,p;
  cin>>a>>p;
  ll r=(a*3+p)/2;
  cout<<r<<endl;
}


Measured memory_bytes: 256
L=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
ans=L[K-1]
print(ans)


Measured memory_bytes: 2940
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a,b := 1,2
	f := false
	for i := 1; i <= n; i++ {
		if i*(i+1) == n*2 {
			a = i
			b = i+1
			f = true
			break
		}
	}

	if !f {
		fmt.Fprintln(wr, "No")
		return
	}


	fmt.Fprintln(wr, "Yes")
	fmt.Fprintln(wr, b)
	s := make([][]int, b)
	for i := 0; i < b; i++ {
		s[i] = make([]int, a)
	}

	c := 1
	for i := 0; i < a; i++ {
		for j := i; j < a; j++ {
			s[i][j] = c
			s[j+1][i] = c
			c++
		}
	}

	for i := 0; i < b; i++ {
		fmt.Fprint(wr, a)
		for j := 0; j < a; j++ {
			fmt.Fprintf(wr," %d", s[i][j])
		}
		fmt.Fprintln(wr)
	}

}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

vector<vector<P>> edges;
vector<int> colors;

void dfs(int root, int col){
    colors[root]=col;
    for(int i=0; i<edges[root].size(); i++){
        if(colors[edges[root][i].first]==-1){
            dfs(edges[root][i].first,(col+edges[root][i].second)%2);
        }
    }
    return;
}

int main(){
    int n;
    cin>>n;
    edges.resize(n);
    colors.resize(n,-1);
    for(int i=0; i<n-1; i++){
        int u,v,w;
        cin>>u>>v>>w;
        edges[u-1].push_back({v-1,w});
        edges[v-1].push_back({u-1,w});
    }
    dfs(0,0);
    for(int i=0; i<n; i++){
        cout<<colors[i]<<endl;
    }



    return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define MAX 1000000
#define pb push_back
#define f first
#define s second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define int long long int
using namespace std;

typedef pair<int, int> pii;
typedef map<int, int> mapint;
typedef vector<int> vi;

int power(int x, int y) 
{ 
    int res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
   
        // n must be even now 
        y = y>>1; // y = y/2 
        x = x*x;  // Change x to x^2 
    } 
    return res; 
}

int32_t main(){
	fio;
	int r;
	cin>>r;
	cout<<3* power(r, 2)<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b) % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");

    }

}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
  static String x;

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

    x = sc.next();
    int n = x.length();

    char[] stack = new char[n];
    int sp = 0, count = 0;
    for(int i = 0; i < n; i++){
      if(x.charAt(i) == 'S'){
        stack[sp++] = 'S';
      }
      else{
        if(sp - 1 >= 0){
          sp--; ++count;
        }
      }
    }

    int ans = n - count * 2;

    System.out.println(ans);
  }
}


Measured memory_bytes: 14988
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    
    int n,ans=0;
    long long int k;
    cin>>n>>k;
    pair<int,int> a[111111];
   
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        k-=a[i].second;
        //cout<<k<<endl;
        if(k<=0){ans=a[i].first;break;}
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main() {
    map<string, int> mp;

    int q;
    cin >> q;
    while (q--) {
        int op;
        string s;
        cin >> op >> s;
        if (op == 0) {
            int x;
            cin >> x;
            mp[s] = x;
        } else if (op == 1) {
            cout << mp[s] << endl;
        } else {
            mp.erase(s);
        }
    }
    return 0;
}



Measured memory_bytes: 27680
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define lli long long int 
#define ull unsigned long long
#define mod 1000000007
#define endl "\n"
#define GIO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{ GIO;
ll x,y,z;
cin>>x>>y>>z;
if((x==5 &&y==5&& z==7)||(x==7&&y==5&& z==5)||(x==5 &&y==7&& z==5))
{cout<<"YES"<<"\n";}
else cout<<"NO"<<"\n";


return 0;
}




Measured memory_bytes: 256
from collections import deque
def solve():
    H,W = map(int,input().split())
    Ch,Cw = map(lambda x:int(x)-1,input().split())
    Dh,Dw = map(lambda x:int(x)-1,input().split())
    A = [list(input()) for _ in range(H)]
    V = [[-1]*W for _ in range(H)]
    d = ((1,0),(0,1),(-1,0),(0,-1))

    def bfs_2d(sy,sx,v):
        que = deque()
        V[sy][sx] = v
        que.append((sy,sx))

        while que:
            uh, uw = que.popleft()
            for dy, dx in d:
                next_h = uh+dy
                next_w = uw+dx
                if 0 <= next_h < H and 0 <= next_w < W \
                    and A[next_h][next_w] == '.' \
                    and V[next_h][next_w] == -1:
                    V[next_h][next_w] = v
                    que.append((next_h,next_w))
    
    vertex = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#' or V[h][w] != -1:
                continue
            bfs_2d(h,w,vertex)
            vertex += 1

    G = [[] for _ in range(vertex)]
    used = [set() for _ in range(vertex)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                continue
            for dh in range(-2, 2+1):
                for dw in range(-2, 2+1):
                    if h + dh < 0 or H <= h + dh or w + dw < 0 or W <= w + dw:
                        continue
                    if A[h+dh][w+dw] == "#":
                        continue
                    if V[h][w] == V[h+dh][w+dw]:
                        continue
                    if V[h+dh][w+dw] in used[V[h][w]]:
                        continue
                    G[V[h][w]].append((V[h+dh][w+dw]))
                    used[V[h][w]].add((V[h+dh][w+dw]))
    
    # s = V[Ch][Cw]
    # g = V[Dh][Dw]

    # dist = [-1 for _ in range(vertex)]
    # que = deque()
    # dist[s] = 0
    # que.append(s)
    # while que:
    #     u = que.popleft()
    #     for v in G[u]:
    #         if dist[v] != -1:
    #             continue
    #         dist[v] = dist[u] + 1
    #         que.append(v)
    
    # print(dist[g])

    start_area_num = int(V[Ch][Cw])
    goal_area_num = int(V[Dh][Dw])

    dist = [-1] * vertex
    dist[start_area_num] = 0
    q = deque()
    q.append((start_area_num,0))
    while len(q) > 0:
        cur_area_num,_ = q.popleft()
        if cur_area_num == goal_area_num:
            print(dist[cur_area_num])
            return
        
        for next_area_num in G[cur_area_num]:
            if dist[next_area_num] == -1:
                dist[next_area_num] = dist[cur_area_num] + 1
                q.append((next_area_num,0))
    else:
        print(-1)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 189948
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())

A = LI()

A_ii = copy.deepcopy(A)
for i in range(N):
    A_ii[i] += i
dic_A_ii = collections.Counter(A_ii)

A_jj = copy.deepcopy(A)

for j in range(N):
    A_jj[j] = -1 * A_jj[j] + j

ans = 0
dic_A_jj = collections.Counter(A_jj)
# print(dic_A_ii)
# print(dic_A_jj)

for ii_key in dic_A_ii.keys():
    ans += dic_A_jj[ii_key] * dic_A_ii[ii_key]

print(ans)

Measured memory_bytes: 65056
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

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

  string t = s.substr(n);
  dbg(s,t);

  map<pair<string,string>, int> ma[2];
  rep(r,2){
    rep(mask, 1<<n){
      string s1,s2;
      rep(i,n) {
        if((mask>>i) % 2) s1.pb(s[i]);
        else s2.pb(s[i]);
      }
      ma[r][{s1, s2}]++;
    }
    swap(s,t);
  }

  long ans = 0;
  for(auto &&pp : ma[0]) {
    string s1 = pp.first.first;
    string s2 = pp.first.second;
    reverse(all(s1));
    reverse(all(s2));
    // if(s1 > s2) swap(s1,s2);
    dbg(pp, s1,s2, ma[1][{s1,s2}]);
    ans += (long)pp.second * ma[1][{s1,s2}];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 132864
import itertools
import numpy as np
from scipy.sparse.csgraph import shortest_path

N,M,R = map(int, input().split())
rs = np.array(list(map(int, input().split()))) -1

nodes = np.full((N,N), np.inf) 
for i in range(M):
  a,b,c = map(int, input().split())
  nodes[a-1,b-1] = nodes[b-1,a-1] = c
min_ds = shortest_path(nodes)
res = float('inf')
for p in itertools.permutations(rs):
  prev = p[0]
  tmp = 0
  for next in p[1:]:
    tmp += min_ds[prev,next]
    prev = next
  res = min(res, tmp)

print(int(res))

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

from itertools import accumulate
from bisect import bisect_left

n, *a = map(int, read().split())
a.sort()
cumsum = list(accumulate(a))
index = bisect_left(cumsum, a[-1] / 2)
cnt = 0
for (bf, af) in zip(cumsum[:index], a[1:index + 1]):
    cnt += 1
    if bf * 2 < af:
        cnt = 0
print((n - index) + cnt)


Measured memory_bytes: 54752
#include <stdio.h>
int no[3];
int main(void)
{
	int ht[10];
	int i,j,k=0;
	
	for (i=0; i<10; i++){
		scanf("%d", &ht[i]);
	}
	
	for (j=0; j<3; j++){
		for (i=0; i<10; i++){
			if (no[j] < ht[i]){
				no[j] = ht[i];
				k=i;
			}
		}
		ht[k] = 0;
		printf("%d\n", no[j]);
	}	
	return 0;
}

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

int main() {
    int s;
    cin >> s;
    set<int> se;
    se.insert(s);
    int i=2;
    while(true) {
        if(s%2==0) s /= 2;
        else s = 3*s+1;
        if(se.find(s)!=se.end()) break;
        else se.insert(s);
        i++;
    }
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b>16)
	{
		cout<<":("<<endl;
		return 0;
	}
	int x,y;
	if(a>=b)
	{
		x=a;
		y=b;
	}
	else
	{
		x=b;
		y=a;
	}
	int ans=x-y;
	int ans1=16-y*2;
	if(ans1%2==1)
	{
		ans1++;
	}
	ans1/=2;
	if(ans1>=ans)
	{
		cout<<"Yay!"<<endl;
	}
	else
	{
		cout<<":("<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++)
        cin >> a.at(i);
    for(int i=n-1; i>=0; i--){
        if(i!=n-1)
            cout << ' ';
        cout << a.at(i);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3112
from collections import deque
INF = 10**9 + 7
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].append([a, b])
    g[b].append([b, a])
res = [[0, INF] for _ in range(n+1)]
res[1][1] = 0
q = deque(g[1])
while q:
    q_ = q.popleft()
    if res[q_[1]][1] == INF:
        for gi in g[q_[1]]: q.append(gi)
        res[q_[1]][0] = q_[0]
        res[q_[1]][1] = res[q_[0]][1] + 1
print("Yes")
for i in res[2:]: print(i[0])

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

#define MAXN 200007

int n ;
string a[ MAXN ] ;

struct node {
    int to[ 26 ] ;
    int subtree ;
    int en ;
    int cnt[ 26 ] ;
    node ( ) {
        subtree = 0 ;
        for ( int i = 0 ; i < 26 ; ++ i ) {
            to[ i ] = cnt[ i ] = 0 ;
        }
    }
};
node v[ 7 * MAXN ] ;
int tpsz = 1 ;

long long ans = 0 ;

void add_word ( string &s ) {
    int sz = s.size ( ) ;
    int aux = 1 ;
    for ( int i = sz - 1 ; i >= 0 ; -- i ) {
        int val = ( s[ i ] - 'a' ) ;
        ++ v[ aux ].subtree ;
        if ( v[ aux ].to[ val ] == 0 ) {
            v[ aux ].to[ val ] = ++ tpsz ;
        }
        aux = v[ aux ].to[ val ] ;
    }
    ++ v[ aux ].subtree ;
    ++ v[ aux ].en ;
}

void upd ( int where ) {
    for ( int i = 0 ; i < 26 ; ++ i ) {
        if ( v[ where ].to[ i ] > 0 ) {
            upd ( v[ where ].to[ i ] ) ;
            for ( int j = 0 ; j < 26 ; ++ j ) {
                if ( i != j ) {
                    v[ where ].cnt[ j ] += v[ v[ where ].to[ i ] ].cnt[ j ] ;
                }
                else {
                    v[ where ].cnt[ j ] += v[ v[ where ].to[ i ] ].subtree ;
                }
            }
        }
    }
}

void calc ( int where ) {
    for ( int i = 0 ; i < 26 ; ++ i ) {
        if ( v[ where ].to[ i ] > 0 ) {
            if ( v[ v[ where ].to[ i ] ].en > 0 ) {
                ans += ( v[ where ].cnt[ i ] - 1 ) ;
            }
            calc ( v[ where ].to[ i ] ) ;
        }
    }
}

void input ( ) {
    cin >> n ;
    for ( int i = 0 ; i < n ; ++ i ) {
        cin >> a[ i ] ;
    }
}

void solve ( ) {
    for ( int i = 0 ; i < n ; ++ i ) {
        add_word ( a[ i ] ) ;
    }
    upd ( 1 ) ;
    calc ( 1 ) ;
    cout << ans << "\n" ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 351216
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n,a,b,c,d,e;
  cin >>n >> a >>b >>c >> d >>e;
  long long int x=min(a,min(b,min(c,min(d,e))));
  if(n%x==0)cout << n/x+4 <<endl;
  else cout << n/x+1+4 <<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    w = input().strip()

    dic = {}
    for c in w:
        if c in dic:
            dic[c] += 1
        else:
            dic[c] = 1
    
    ok = True
    for key, value in dic.items():
        if value&1:
            ok = False
            break
    
    if ok:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
using namespace std;
#define SEQ 3

int main(){
	int table[SEQ];
	int i;
	cin >> table[0] >> table[1] >> table[2];
	sort(table, table+SEQ);
	for (i = 0; i < SEQ-1; i++){
		cout << table[i] << " ";
	}
	cout << table[SEQ-1] << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,p,k;
string s,t;

int main(){
    cin >> n >> s >> t; p=2*n;
    for(int i=1;i<=n;i++){
        k=1;
        for(int j=0;j<i;j++){
            if(s[n-i+j]!=t[j]) k=0;
        }
        if(k) p=2*n-i;
    }
    cout << p;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
            int r = scanner.nextInt();
            int c = scanner.nextInt();
            int[][] table = new int[r+1][c+1];
            for (int i=0; i<r; i++) {
                for (int j=0; j<c; j++) {
                    table[i][j] = scanner.nextInt();
                }
            }
            for (int i=0; i<r; i++) {
                int sum = 0;
                for (int j=0; j<c; j++) {
                    sum += table[i][j];
                }
                table[i][c] = sum;
            }
            for (int i=0; i<c+1; i++) {
                int sum =0;
                for (int j=0; j<r; j++) {
                     sum += table[j][i];
                }
                table[r][i] = sum;
            }
            for (int i=0; i<=r; i++) {
                for (int j=0; j<=c; j++) {
                    if(j==0) {
                        System.out.print(table[i][j]);
                    } else {
                        System.out.print(" " + table[i][j]);
                    }
                    
                }
                System.out.println("");
            }
    }
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define pii pair<int,int>
#define pll pair<ll, ll>
#define forn(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007

ll dp[100005];

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n, W;
	cin >> n >> W;
	forn(i, 0, 100004){
		dp[i] = 1e18;
	}
	dp[0] = 0;
	forn(i, 0, n - 1){
		ll a, b;
		cin >> a >> b;
		
		ford(j, 100000, b){
			dp[j] = min(dp[j], dp[j - b] + a);
		}
	}

	ford(i, 100000, 0){
		if(dp[i] <= W){
			cout << i << "\n";
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int dp[70][2][2];
int lb,rb;
int dfs(int pos,int llim,int rlim,int zero){
    if(pos==-1)return 1;
    if(dp[pos][llim][rlim]!=-1)return dp[pos][llim][rlim];
    int lf=0;
    int rf=1;
    if(llim)lf=lb>>pos&1;
    if(rlim)rf=rb>>pos&1;
    int ans=0;
    for(int i=lf;i<=1;++i){
        for(int j=i;j<=rf;++j){
            if(j==1&&zero){
                if(i==1)ans+=dfs(pos-1,(i==lf)&&llim,(j==rf)&&rlim,zero&&j==0);
            }
            else ans+=dfs(pos-1,(i==lf)&&llim,(j==rf)&&rlim,zero&&j==0);
        }
    }
    ans%=mod;
    if(!zero)dp[pos][llim][rlim]=ans;
    return ans;
}
main(){
    cin>>lb>>rb;
    memset(dp,-1,sizeof(dp));
    cout<<dfs(63,1,1,1)<<endl;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

const int inf = 1e18;

int N, M, X;
int C[20];
int A[20][20];
int alg[20];

bool check() {
	rep (i, M) {
		if (alg[i] < X) return false;
	}
	return true;
}

int dfs(int idx) {
	if (idx >= N) {
		if (check()) {
			return 0;
		} else {
			return inf;
		}
	} else {
		int ret = 0;

		// 選ぶ
		rep (i, M) { alg[i] += A[idx][i]; }
		int a = C[idx] + dfs(idx + 1);
		rep (i, M) { alg[i] -= A[idx][i]; }

		// 選ばない
		int b = dfs(idx + 1);

		ret += min(a, b);

		return ret;
	}
}

signed main() {
	cin >> N >> M >> X;
	rep (i, N) {
		cin >> C[i];
		rep (j, M) {
			cin >> A[i][j];
		}
	}

	int res = dfs(0);
	if (res >= inf) {
		res = -1;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
const int N = 2e5 + 1;
bool isprime[N];
int dp[N];
void prime_gen(){
  fill(isprime + 2,isprime + N,true);
  for(int i = 2; i < N; i++){
	  if (isprime[i]){
		  for(int j = 2 * i; j < N; j+=i){
			 isprime[j] = false;  
		   }  
		}
	}	
}

void precompute(){
  	for(int i = 3; i < N ;i += 2){
	   if (isprime[i] and isprime[(i+1)/2]){
		    dp[i]++;  
		 }
	}
	for(int i = 3; i < N; i++){
	  dp[i] += dp[i-1];	
    }
}

void solve(){
   prime_gen();
   precompute();
   int q;
   cin >> q;
   while (q--){
	   int l, r;
	   cin >> l >> r;
	   int ret = dp[r] - dp[l-1];
	   cout << ret << endl;
	 }
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 2432
// Aizu 2182: Eleven Lover
// 2017.9.20 bal4u@uu

#include <stdio.h>
#include <string.h>

char a[80005];
int dp[2][11];

int main()
{
	int i, d, k1, k2, ans;
	char *p;

	while (scanf("%s", a) && *a != '0') {
		memset(dp, 0, sizeof(dp)); ans = 0;
		for (k1 = 0, k2 = 1, p = a; *p; k1 = k2, k2 = !k2) {
			for (i = 0; i < 11; i++) dp[k2][i] = 0;
			d = *p++ - '0';
			for (i = 0; i < 11; i++) dp[k2][(10*i+d) % 11] += dp[k1][i]; 
			ans += dp[k2][0];
			if (d > 0) dp[k2][d]++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
const long long inf=1e10;
long long n, w, V=0, dp[100005], wi[105], vi[105];
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> n >> w;
	for(int i=1;i<=n;i++){
		cin >> wi[i] >> vi[i];
		V+=vi[i];
	}
	for(int i=0;i<=V;i++){
		dp[i]=inf;
	}
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=V;j>=vi[i];j--){
			dp[j]=min(dp[j], dp[j-vi[i]]+wi[i]);
		}
	}
	for(int i=V;i>=0;i--){
		if(dp[i]<=w){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef long long LL;

const int maxn = 200009;
LL c[maxn], sum[maxn], x[maxn], ans;
int n, K, a, m;

int del(){
	int m = 1;
	for (int i=2; i<=n+1; i++)
		if (x[i] != x[i-1]) x[++m] = x[i];
	return m;
}

int search(LL k){
	int l = 1, r = m, mid;
	while (l < r){
		mid = (l + r) >> 1;
		if (k <= x[mid]) r = mid;
		else l = mid + 1;
	}
	return l;
}

void update(int x){
	for (; x<=m; x+=lowbit(x)) c[x]++;
}

int query(int x){
	int res = 0; for (; x; x-=lowbit(x)) res += c[x]; return res;
}

int main(){
	scanf("%d%d", &n, &K);
	for (int i=1; i<=n; i++){
		scanf("%d", &a);
		sum[i] = sum[i-1] + a - K;
		x[i] = sum[i];
	}
	sort(x+1, x+n+2); m = del();
	update(search(0));
	for (int i=1; i<=n; i++){
		ans += query(search(sum[i]));
		update(search(sum[i]));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
const int Keta_MAX = 1000000;
string S;
int keta;
auto memo = make_v<ll>(Keta_MAX + 1, 2);
ll solve(int k, bool pitari)
{

    int now = S[k] - '0';
    if (k == keta)
    {
        return pitari == false;
    }
    if (memo[k][pitari] != -1)
        return memo[k][pitari];
    if (pitari)
    {
        memo[k][pitari] = min(now + solve(k + 1, true), now + 1 + solve(k + 1, false));
    }
    else
    {
        memo[k][pitari] = min(9 - now + solve(k + 1, false), 10 - now + solve(k + 1, true));
    }
    return memo[k][pitari];
}
int main()
{
    fill_v(memo, -1);

    cin >> S;
    keta = S.size();
    cout << min(solve(0, true), solve(0, false) + 1);
    return 0;
}

Measured memory_bytes: 134300
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    if (x<1200)
        cout<<"ABC";
    else if (x<2800)
        cout<<"ARC";
    else
        cout<<"AGC";
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    N = int(input())

    ans = 0
    for _ in range(N):
        x, u = input().split()
        if u=='JPY':
            ans += int(x)
        else:
            ans += float(x) * 380000.0
    
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;
using namespace chrono;

//  https://ja.wikipedia.org/wiki/Xorshift
int xor64(void) {
    static unsigned long long x = 88172645463325252ULL;
    x ^= x<<13;
    x ^= x>> 7;
    x ^= x<<17;
    return int(x&0x7fffffff);
}

int main()
{
    //  入力
    int D;
    cin>>D;
    vector<int> C(26);
    for (int &c: C)
        cin>>c;
    vector<vector<int>> S(D, vector<int>(26));
    for (auto &s: S)
        for (auto &x: s)
            cin>>x;

    auto start = system_clock::now();

    //  選んだコンテスト
    vector<int> T(D, -1);

    int score = 0;
    for (int t=0; t<26; t++)
        score -= C[t]*D*(D+1)/2;

    //  d日目にコンテストtを開く
    auto add = [&](int d, int t)
    {
        int d0 = d;
        while (d0>=0 && T[d0]!=t)
            d0--;
        int d1 = d;
        while (d1<D && T[d1]!=t)
            d1++;
        score += C[t]*(d-d0)*(d1-d);
        score += S[d][t];
        T[d] = t;
    };

    //  d日目のコンテストを止める
    auto remove = [&](int d)
    {
        int t = T[d];
        T[d] = -1;
        int d0 = d;
        while (d0>=0 && T[d0]!=t)
            d0--;
        int d1 = d;
        while (d1<D && T[d1]!=t)
            d1++;
        score -= C[t]*(d-d0)*(d1-d);
        score -= S[d][t];
    };

    for (int d=0; d<D; d++)
        add(d, d%26);

    double time = 0.0;
    double limit = 1.8;

    int step;
    for (step=0; time<limit; step++)
    {
        if (step%10000==0)
            time = duration_cast<microseconds>(system_clock::now()-start).count() * 1e-6;

        if (step%2==0)
        {
            //  1日のコンテストの種類を変えてみる
            int d = xor64()%D;
            int t = xor64()%26;
            int old_score = score;
            int old_t = T[d];
            remove(d);
            add(d, t);

            //  悪くなったら戻す
            if (score < old_score)
            {
                remove(d);
                add(d, old_t);
            }
        }
        else
        {
            //  x日以内のコンテストを交換してみる
            //  xは時間とともに小さくする（焼きなまし）
            int x = max(1, int(14*(limit-time)/limit));
            int d0 = xor64()%D;
            int d1 = d0 + xor64()%(2*x+1) - x;
            if (d1!=d0 && 0<=d1 && d1<D)
            {
                int old_score = score;
                int t0 = T[d0];
                int t1 = T[d1];
                remove(d0);
                remove(d1);
                add(d0, t1);
                add(d1, t0);

                //  悪くなったら戻す
                //  ただし、ある程度までは許容する
                //  許容範囲は時間とともに狭める（焼きなまし）
                if (score < old_score - int(10'000*(limit-time)/limit))
                {
                    remove(d0);
                    remove(d1);
                    add(d0, t0);
                    add(d1, t1);
                }
            }
        }
    }

    for (int t: T)
        cout<<t+1<<endl;

    cerr<<"score: "<<max(0, score+1000000)<<endl;
    cerr<<"step: "<<step<<endl;
}


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

int main() {
    int N;
    cin >> N;
    map<int, int> even, odd;
    for (int i = 0; i < N; i++) {
        int v;
        cin >> v;
        if (i % 2 == 0) {
            even[v]++;
        } else {
            odd[v]++;
        }
    }

    vector<pair<int, int>> v0, v1;
    for (auto p : even) {
        v0.push_back({p.second, p.first});
    }
    for (auto p : odd) {
        v1.push_back({p.second, p.first});
    }
    v0.push_back({0, -1e9});
    v1.push_back({0, -1e9});
    sort(v0.begin(), v0.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
        return a.first > b.first;
    });
    sort(v1.begin(), v1.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
        return a.first > b.first;
    });

    if (v0[0].second == v1[0].second) {
        cout << min(N - v0[1].first - v1[0].first, N - v0[0].first - v1[1].first) << endl;
    } else {
        cout << N - v0[0].first - v1[0].first << endl;
    }
}


Measured memory_bytes: 6136
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
pn = list(map(int, input().split()))

count = 0
big_index = [] # 昇順できないデータを入れておく
for i in range(N):
    if pn[i] != i+1:
        count += 1
if count <= 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38384