akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

long long n, m, a;

int main(){

    unordered_map<long long, long long> um;
    vector<long long> v;

    cin >> n;

    for(long long i = 0; i < n; i++){
        cin >> a;
        um[a]++;
    }

    cin >> m;

    for(long long i = 0; i < m; i++){
        cin >> a;
        v.push_back(a);
    }

    for(long long i = 0; i < v.size(); i++){
        if(um[v[i]] == 0){
            cout << "NO";
            return 0;
        } else{
            um[v[i]]--;
        }
    }

    cout << "YES";






}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 11592
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    string s; cin >> s;
    int cnt[26] = {0};
    int res[10] = {0};

    rep(i, n)++cnt[s[i++] - 'a'];
    rep(i, 26)++res[cnt[i]];
    int x = 0, ans = 0;
    for(i = 2;i < 10;++i)if(res[i] > 0){
      if(res[i] == 1)ans += 4;
      else ans += 1 + 2 + 2 + res[i] + res[i] - 1;
    }
    if(res[1] > 0)ans += res[1] + res[1];
    pri(ans - 1);


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3276
#include <iostream>
#include <string>

using namespace std;

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

	int pairA[2] = { -1, -1 };
	int pairB[2] = { -1, -1 };

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; i < 4; j++)
		{
			// 自分同士はパス
			if (j == i)
				continue;

			// ペアが見つかった場合、IDを登録
			if (s[j] == s[i])
			{
				pairA[0] = i;
				pairA[1] = j;

				// 残りのIDを探す
				for (int k = 0; k < 4; k++)
				{
					if (k == pairA[0] || k == pairA[1])
						continue;

					if (pairB[0] == -1)
						pairB[0] = k;
					else
						pairB[1] = k;
				}

				// 残っている文字でペア成立
				if (s[pairB[0]] == s[pairB[1]])
				{
					// ペアAとペアBで別の文字なら"Yes"を出力して終了
					if (s[pairA[0]] != s[pairB[0]])
					{
						cout << "Yes";
						return 0;
					}
					else // 全部同じなら"No"を出力して終了
					{

						cout << "No";
						return 0;
					}
				}
				else // 不成立なら"No"を出力して終了
				{
					cout << "No";
					return 0;
				}

			}

		}

	}


	cout << "No";
	return 0;
}

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

int main(){
	priority_queue<int> q;
	string str;
	int data;
	while(1){
		cin>>str;
		if(str=="end")	break;
		else if(str=="insert"){
			cin>>data;
			q.push(data);
		}
		else if(str=="extract"){
			cout<<q.top()<<endl;
			q.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 7300
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int x; scanf("%d", &x);
	
	printf("%d\n", 1 - x);
	return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
    int A,B,C;

    
    cin >> A >> B >> C;
    
    int ans = C- (A - B);
    
    if (ans < 0) ans=0;
    
    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int N,i,j;
	cin>>N;
	long long int arr[N][3];
	long long int s[N][3];
	cin>>arr[0][0];
	cin>>arr[0][1];
	cin>>arr[0][2];
  
     s[0][0]=arr[0][0];
     s[0][1]=arr[0][1];
     s[0][2]=arr[0][2];
     for (i = 1; i < N; ++i)
     {
     	cin>>arr[i][0];
     	cin>>arr[i][1];
     	cin>>arr[i][2];

     	s[i][0]=max(arr[i][0]+s[i-1][1],arr[i][0]+s[i-1][2]);

     	s[i][1]=max(arr[i][1]+s[i-1][0],arr[i][1]+s[i-1][2]);

     	s[i][2]=max(arr[i][2]+s[i-1][1],arr[i][2]+s[i-1][0]);
     	
     }
     cout<<max(s[N-1][0],max(s[N-1][1],s[N-1][2]));
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#include<bitset>

#define MOD 1000000007
using namespace std;

int main()
{
	int ans = 0;
	int N, X;	cin >> N >> X;
	vector<int> L(N);

	for (int i = 0; i < N; i++)
	{
		cin >> L[i];
	}
	int count = 1;
	int i = 0;
	while (ans <= X&&i<L.size()) 
	{
		ans += L[i];
		i++;
		count++;
		if (ans <= X && i == L.size())	count++;
	}

	count--;

	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e15;
const int inf=1e9;
const ll MOD=1000000007;

int main(){
    ll N;cin>>N;
    if(N%2){
        cout<<0<<endl;
        return 0;
    }
    ll ans=0,k=N;
    k=N/10;
    ans+=k;
    while(k){
        ans+=k/5;
        k/=5;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long a,b,n,ans=0;
    cin>>a>>b>>n;
    long long best=-1;
    if(n>=b-1)
        n=b-1;
    best = a*n/b-a*(n/b);

    cout<<best;
}


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

int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flag = 1;
    for(int i = 0; flag;i++) {
        flag=0;
        for(int j=N-1;j>=i+1;j--) {
            if(A[j] < A[j -1]) {
                swap(A[j], A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main() {
    int A[100], N,sw;
    cin >> N;
    for(int i=0; i <N;i++) cin >> A[i];
    
    sw = bubbleSort(A, N);
    
    for(int i =0; i <N; i++) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3104
def print_arr(arr):
    for i in range(len(arr)):
        if i != len(arr) - 1:
            print(arr[i], end=' ')
        else:
            print(arr[i], end='')
    print()

if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    print_arr(arr)
    for i in range(1, len(arr)):
        v = arr[i]
        j = i - 1
        while j >= 0 and arr[j] > v:
            arr[j + 1] = arr[j]
            j -= 1
        arr[j + 1] = v
        print_arr(arr)



Measured memory_bytes: 5980
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * The Secret Number
 */
public class Main {

	static final String EMPTY = "";

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int W, H;
			W = parseInt(line.substring(0, line.indexOf(' ')));
			H = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((W | H) == 0) break;

			char[][] numc;
			String[][] nums;

			numc = new char[H + 1][W + 1];
			nums = new String[H + 1][W + 1];

			for (int i = 0; i < numc.length; i++) {
				Arrays.fill(numc[i], 'X');
			}

			for (int i = 0; i < H; i++) {
				line = br.readLine();
				for (int j = 0; j < W; j++) {
					char c = line.charAt(j);
					numc[i][j] = (c <= '9' ? c : 'X');
				}
			}

			//solve
			for (int i = H - 1; i >= 0; i--) {
				for (int j = W - 1; j >= 0; j--) {
					if (numc[i][j] != 'X') {
						String s1 = (numc[i + 1][j] != 'X' ? nums[i + 1][j] : EMPTY);
						String s2 = (numc[i][j + 1] != 'X' ? nums[i][j + 1] : EMPTY);
						nums[i][j] = numc[i][j] + large(s1, s2);
					}
				}
			}

			String max = EMPTY;

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (numc[i][j] != 'X') {
						nums[i][j] = nums[i][j].replaceFirst("^0+", EMPTY);
						max = large(max, nums[i][j]);
					}
				}
			}

			System.out.println(max);

		} //end while

	} //end main

	static String large(String s1, String s2) {

		if (s1.length() > s2.length()) return s1;
		if (s1.length() < s2.length()) return s2;
		if (s1.equals(s2)) return s1;

		String ret = EMPTY;
		for (int i = 0; i < s1.length(); i++) {
			if (s1.charAt(i) > s2.charAt(i)) {
				ret = s1;
				break;
			} else if (s1.charAt(i) < s2.charAt(i)) {
				ret = s2;
				break;
			}
		}
		return ret;
	}
}

Measured memory_bytes: 64864
#include "bits/stdc++.h"
#include <random>

using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll D=365;
vi c(26);
vi last(26,-1);
vvi dat(D, vi(26));  // N * M の2次元配列
vvi AAlist(D, vi(D));  // N * M の2次元配列




ll calcscore(vi &Alist)
{
  for(ll i=0;i<26;i++){
    last[i]=-1;
  }
  

  ll sc=0;
  ll sct=0;
  ll l;
  ll id;
  ll factscore=0;
  for(ll i=0;i<D;i++){
    sc=-922337203685477580LL;
    for(ll j=0;j<26;j++){
      if (Alist[i]==j)continue;
      l=i-last[j];
      sct=l*c[j];
      factscore-=sct;
    }

    id=Alist[i];
    factscore+=dat[i][id];
    last[id]=i;
  }

  return factscore;
}



void makeseed(int xid,int startoffset)
{

  ll sc=0;
  ll sct=0;
  ll maxid=-1;
  ll factscore=0;
  
  for(ll i=0;i<26;i++){
    last[i]=startoffset-1;
  }

  for(ll i=startoffset;i<D;i++){
    sc=-922337203685477580LL;
    maxid=0;
    
    for(ll j=0;j<26;j++){
      ll l=i-last[j];
      
      l*=(l-1-l*5/6);
      sct=l*c[j];
      factscore-=sct;
      sct=dat[i][j]+sct;
      if (sc<sct){
        sc=sct;
        maxid=j;
      }
    }
    factscore+=sc;
    last[maxid]=i;
    AAlist[startoffset][i]=maxid;
    //cout<<(maxid+1)<<endl;
  }


}





int main(){
  ll ans=0;
  ll debug=0;//本番では0に
  cin>>ans;
  ll factscore=0;


  for(ll i=0;i<26;i++){
    cin>>c[i];
  }
  for(ll i=0;i<D;i++){
    for(ll j=0;j<26;j++){
      cin>>dat[i][j];
    }
  }


  for(ll i=0;i<60;i++){
    makeseed(0,i);
  }
  



  for(ll i=1;i<60;i++){
    for(ll j=0;j<i;j++){
      AAlist[i][j]=AAlist[i-1][j];
    }
  }
  
  ll score=-922337203685477580LL;
  ll ansid=0;




  score=-922337203685477580LL;
  
  for(ll i=0;i<60;i++){
    if (score<calcscore(AAlist[i])){
      score=calcscore(AAlist[i]);
    }
  }




  random_device rnd;
  ll loopcnt=0;
  for(ll i=60;i<D;i++){
    ll aaa=rnd()%D;
    ll ref1=rnd()%60;
    ll ref2=rnd()%60;
    loopcnt++;
    if (loopcnt>180000)break;
    for(ll j=0;j<aaa;j++){
      AAlist[i][j]=AAlist[ref1][j];
    }
    
    for(ll j=aaa;j<D;j++){
      AAlist[i][j]=AAlist[ref2][j];
    }

    if (score>calcscore(AAlist[i]))
    {
      i--;
      continue;
    }
    
  }


















  score=-922337203685477580LL;
  ansid=0;
  for(ll i=0;i<D;i++){
    if (score<calcscore(AAlist[i])){
      score=calcscore(AAlist[i]);
      ansid=i;
    }

    if (debug==1){
      cout<<calcscore(AAlist[i])<<endl;
    }

  }



  if (debug==0)
  {
    for(ll i=0;i<D;i++){
      cout<<(AAlist[ansid][i]+1)<<endl;
    }
  }else{
    cout<<calcscore(AAlist[ansid])<<endl;
  }
    

  return 0;
}

/*
1万
36万
92万
*/

Measured memory_bytes: 4768
#include <stdio.h>

int main()
{
	int H, W, A, B;
	scanf("%d %d %d %d", &H, &W, &A, &B);
	
	int i, j;
	for (i = 0; i < B; i++) {
		for (j = 0; j < A; j++) printf("1");
		for (; j < W; j++) printf("0");
		printf("\n");
	}
	for (; i < H; i++) {
		for (j = 0; j < A; j++) printf("0");
		for (; j < W; j++) printf("1");
		printf("\n");
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    vector<ll> t(2),a(2),b(2);
    rep(i,2) cin >> t[i];
    rep(i,2) cin >> a[i];
    rep(i,2) cin >> b[i];
    rep(i,2){
        a[i]*=t[i];
        b[i]*=t[i];
    }
    if (a[0]+a[1]==b[0]+b[1]){
        cout << "infinity" << endl;
        return 0;
    }
    if (a[0]+a[1]<b[0]+b[1]){
        swap(a[0],b[0]);
        swap(a[1],b[1]);
    }
    if (a[0]>b[0]){
        cout << 0 << endl;
        return 0;
    }
    ll p=b[0]-a[0],q=a[0]+a[1]-b[0]-b[1];
    ll x=p/q;
    if (p%q==0) cout << 2*x << endl;
    else cout << 2*x+1 << endl;
}

Measured memory_bytes: 256
A, B, K = map(int,input().split())
r1 = A
r2 = B
if A >= K:
  r1 = A - K
elif B > (K - A):
  r1 = 0
  r2 = r2 - (K - A)
else:
  r1 = 0
  r2 = 0
print(r1, r2)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
	int a, b, c;
	char op;

	for (;;)
	{
		scanf("%d %c %d", &a, &op, &b);

		if (op =='+')
		{
			c=a+b;
			printf("%d\n", c);
		}

		else if (op =='-')
		{
			c=a-b;
			printf("%d\n", c);
		}

		else if (op =='*')
		{
			c=a*b;
			printf("%d\n", c);
		}

		else if (op =='/')
		{
			c=a/b;
			printf("%d\n", c);
		}

	    else

	    	return 0;
	}

	return 0;
}

Measured memory_bytes: 600
c={}
for i=1,3 do
    c[i]={}
    for j=1,3 do
        c[i][j]=io.read("*n")
    end
end

checker={}
for i=1,3 do
    checker[i]={}
    for j=2,3 do
        x=c[i][j-1]-c[i][j]
        table.insert(checker[i],x)
    end
end

takahashi=true
for i=2,3 do
    if checker[i][1]~=checker[i-1][1] or checker[i][2]~=checker[i-1][2] then
        takahashi=false
    end
end

if takahashi then
    print("Yes")
else
    print("No")
end

Measured memory_bytes: 888
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=sort(parseMap(split(readline())))
    cnt=0
    for i in 1:n
        if a[i]<0
            a[i]*=-1
            cnt+=1
        else
            break
        end
    end
    sort!(a,by=abs)
    if cnt%2==1
        a[1]*=-1
    end
    println(sum(a))
end
main()

Measured memory_bytes: 121480
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		String S=stdIn.next();
		int ans=0;
		for(int i=0;i<N-2;i++){
			if(S.substring(i,i+3).equals("ABC"))
				ans++;
		}
		System.out.println(ans);
	}
}


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

using namespace std;

bool is_prime(int);

int main(){
    int n;
    cin>>n;
    int *a=new int[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int count = 0;
    for(int i=0;i<n;i++){
        if(is_prime(a[i]))count++;
    }
    cout<<count<<endl;
}

bool is_prime(int a){
    if(a<=1)return false;
    if(a==2)return true;
    if(a%2==0)return false;
    for(int i=3;i<=sqrt(a);i+=2){
        if(a%i==0)return false;
    }
    return true;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;

int N, M, k[10], s[10][10], p[10], S[10] = { 0 };

int repeat(int n) {
	if (n == N) {
		int count = 0;
		bool allOn = true;
		rep(i, M) { // 電球iに対して、
			int on = 0;
			rep(j, k[i]) {
				rep(k, N) {
					// 電球iがスイッチkを使っていて、かつ、スイッチkがonなら、
					if (s[i][j] == k + 1 && S[k] == 1) {
						on += 1;
					}
				}
			}
			if (on % 2 != p[i]) {
				allOn = false;
			}
		}
		if (allOn) {
			count += 1;
		}
		return count;
	}
	int total = 0;
	S[n] = 0;
	total += repeat(n + 1);
	S[n] = 1;
	total += repeat(n + 1);
	return total;
}

int main() {
	cin >> N >> M;
	rep(i, M) {
		cin >> k[i];
		rep(j, k[i]) {
			cin >> s[i][j];
		}
	}
	rep(i, M) {
		cin >> p[i];
	}
	cout << repeat(0) << endl;
}

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

int main(){
  ll n; cin >> n;
  string s; cin >> s;
  ll rnum = 0, gnum = 0, bnum = 0;
  for(char x : s){
    if (x == 'R') ++rnum;
    if (x == 'G') ++gnum;
    if (x == 'B') ++bnum;
  }
  ll res = rnum * gnum * bnum;
  for(ll i=1; i*2<n; ++i){
    for(ll j=0; j+2*i<n; ++j){
      if(s[j] != s[j+i] && s[j+i] != s[j+2*i] && s[j+2*i] != s[j]) --res;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    ll a[101010], sum[101010];

    map<ll,int> m;
    sum[0] = 0;
    REP(i,N) cin >> a[i];
    REP(i,N) sum[i+1] = a[i] + sum[i];
    REP(i,N+1) ++m[sum[i]%M];
    
    ll ans = 0;
    for(auto itr : m) {
        ll num = itr.first;
        ll cnt = itr.second;
        ans += cnt * (cnt-1) / 2;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    ll N;
    cin >> N;
    vector<ll>L(N);
    ll cnt = 0;
    rep(i, N) cin >> L[i];
    for(int i=0; i<N-2; ++i){
        for(int j=i+1; j<N-1; ++j){
            for(int k=j+1; k<N; ++k){
                if(L[i]==L[j]||L[j]==L[k]||L[i]==L[k]) continue;
                ll ma = max({L[i], L[j], L[k]});
                ll su = L[i]+L[j]+L[k];
                if(ma<su-ma){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3620
#pragma GCC optimize("O3")
#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 <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s; cin>>s;

    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 764
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <tuple>
using namespace std;

int main() {
	char S[2 * 100000 + 1];
	char T[2 * 100000 + 1];

	int dummy;
	dummy = scanf("%s", S);
	dummy = scanf("%s", T);

	map<char, char> mcc;
	char next = 'a';

	for (int i = 0; S[i] != 0; i++) {
		if (!mcc.count(S[i])) {
			mcc[S[i]] = next;
			next++;
		}
		S[i] = mcc[S[i]];
	}

	mcc.clear();
	next = 'a';
	for (int i = 0; T[i] != 0; i++) {
		if (!mcc.count(T[i])) {
			mcc[T[i]] = next;
			next++;
		}
		T[i] = mcc[T[i]];
	}

	if (strcmp(S, T)) printf("No");
	else printf("Yes");

	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n == 0 || n == 1){
    return dp[n] = 1;
  }
  
  if(dp[n] != -1){
    return dp[n];
  }
  
  return dp[n] = fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  
  for(i = 0; i < 50; i++){
    dp[i]=-1;
  }
  
  scanf("%d", &n);
  printf("%d\n", fib(n));
  
  return 0;
}




Measured memory_bytes: 2108
N = int(input())
D = [[0 for x in range(10)] for y in range(10)]

for x in range(1,N + 1):
    s = int(str(x)[0])
    t = int(str(x)[-1])
    D[s][t] += 1

ans = 0
for x in range(10):
    for y in range(10):
        ans += D[x][y] * D[y][x]
print(ans)

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll dp[101010];

ll dfs(Graph& g,Array& used, int v){
	if(used[v]) return dp[v];
	used[v]=true;
	dp[v]=0;
	for(auto e:g[v]){
		chmax(dp[v],dfs(g,used,e.to)+1);
	}
	return dp[v];
}

void solve(){
	ll n;
	cin>>n;

	vec<double> p(n);
	REP(i,n) cin>>p[i];


	vvec<double> dp(n+1, vec<double>(n+1,0));//iこめまでみて、jこあたり
	dp[0][0]=1.0;

	REP(i,n){
		REP(j,i+1){
			dp[i+1][j] += dp[i][j]*(1.0 - p[i]);//はずれ
			dp[i+1][j+1] += dp[i][j]*p[i];//あたり
		}
	}

	double ans=0.0;
	REP2(i,n+1){
		if(n-i >= i) break;
		ans+=dp[n][i];
	}
	cout << fixed << setprecision(10) << ans << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}

Measured memory_bytes: 71552
#ABC51-B

K,S=map(int,input().split())
sum=0
count=0
for i in range(K+1):
    sum+=i
    a=sum
    L=S-sum
    #print(L)
    LL=min(L,K)
    for j in range(LL+1):
        sum+=j
        if S-sum>=0 and S-sum<=K :
            count+=1
            #print(str(i)+" "+str(j))
        sum=a #jを足す前に戻す
    sum=0
print(count)          

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

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

    ll ans = 0;
    rep(i, N+1) {
        if ((i%5 != 0) && (i%3 != 0)) ans += i;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define MAX_N 50

using namespace std;

bool canInsertAt(string S, int Sindex, string T) {
	for (int i = 0; i < T.length(); i++) {
		if (i + Sindex >= S.length()) return false;
		if (S[Sindex + i] != '?' && S[Sindex + i] != T[i]) {
			return false;
		}
	}
	return true;
}

bool canInsert(string S, string T) {
	for (int i = 0; i < S.length(); i++) {
		if (canInsertAt(S, i, T) == true) return true;
	}
	return false;
}

int greatestInsertableIndex(string S, string T) {
	int index = 0;
	for (int i = 0; i <= S.length() - T.length(); i++) {
		if (canInsertAt(S, i, T)) index = i;
	}
	return index;
}

string replaceStringAt(string S, int index, string T) {
	for (int i = 0; i < T.length(); i++) {
		S[index + i] = T[i];
	}
	return S;
}

string replaceQuestionWitha(string S) {
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == '?') S[i] = 'a';
	}
	return S;
}

int main()
{
	string s, t;
	cin >> s >> t;
	if (canInsert(s, t) == false) {
		cout << "UNRESTORABLE" << endl;
	}else{
		int i = greatestInsertableIndex(s, t);
		cout << replaceQuestionWitha(replaceStringAt(s,i,t)) << endl;
	}
	
	
	return 0;
}

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

using namespace std;

int main(){
  int num;
  cin >> num;
  vector<int> x(num);
  for(int i=0;i<num;i++){
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  
  for(int i=1; i<x.size(); i++){
    if(x.at(i) == x.at(i-1)){
        cout << "NO" << endl;
      	return 0;
    }
  }
  
  cout << "YES " << endl;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        a: usize,
        b: usize,
    }
    println!("{}", (a - 1) * (b - 1));
}


Measured memory_bytes: 4352
while True:
    n,x=[int(i) for i in input().split()]
    if n==0 and x==0:
        break
    s=0    
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    s+=1
    print(s) 


Measured memory_bytes: 5604
import java.util.Scanner;
import java.util.TreeSet;

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

    int N = scanner.nextInt();
    char[] S = scanner.next().toCharArray();
    TreeSet<Integer>[] trees = new TreeSet[26];
    for (int i = 0; i < 26; i++) trees[i] = new TreeSet<>();
    for (int i = 0; i < N; i++) trees[S[i] - 'a'].add(i);

    int Q = scanner.nextInt();
    for (int i = 0; i < Q; i++) {
      int type = scanner.nextInt();
      switch (type) {
        case 1:
          int p = scanner.nextInt() - 1;
          char c = scanner.next().charAt(0);
          trees[S[p] - 'a'].remove(p);
          trees[c - 'a'].add(p);
          S[p] = c;
          break;
        case 2:
          int l = scanner.nextInt() - 1;
          int r = scanner.nextInt() - 1;
          int cnt = 0;
          for (int j = 0; j < 26; j++) {
            Integer left = trees[j].ceiling(l);
            if (left != null && left <= r) cnt++;
          }
          System.out.println(cnt);
          break;
      }
    }
  }
}


Measured memory_bytes: 105100
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;

int main(){
  int n,input,x,cnt;
  cin >> n;
  int open[n][10] ;
  int P[n][11];
  int maxSales = INT_MIN;
  int sumSales ;
  vector<int> sales(n,0);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> input;
      open[i][j] = input;
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 11; j++){
      cin >> input;
      P[i][j] = input;
    }
  }

  for(int i = 1 ; i < (1<<10); i++){
    x = i;
    cnt = 0;
    sumSales = 0;
    //i番目のbitが立っていたら加算
    while(x != 0){
      if(x%2){
        for(int j = 0; j < n; j++){
          sales[j] += open[j][cnt];
        }
      }
      x/=2;
      cnt++;
    }

    for(int j = 0; j < n; j++) sumSales += P[j][sales[j]];

    maxSales = max(sumSales,maxSales);

    sales =  vector<int>(n,0);
  }
  cout << maxSales << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int number;
  int count = 0;
  
  cin >> number;
  
  for (int i = 0; i < number; i++) {
    int start, end;
    cin >> start >> end;
    count += end - start + 1;
  }
  
  cout << count << endl;
}

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

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N, 0);
    rep(i, 0, N){
        ll a; cin >> a;
        A[a-1]++;
    }
    ll ans = 0;
    sort(A.begin(), A.end());
    rep(i, 0, N-K) ans += A[i];
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = min(n * a, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

k, = [int(i) for i in read().split()]


v = 7%k
for i in range(k+2):
    if v==0:
        print(i+1)
        break    
    v = (v*10+7)%k
else:
    print(-1)


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

int main() {
    int N, sum;
    cin >> N;
    sum = 0;

    rep(i, N) {
        int r, l;
        cin >> r >> l;
        sum += l - r + 1;
    }

    cout << sum << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, m, x; cin >> n >> m >> x;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    int cnt = 0;
    rep(i, m) {
        if (a[i] < x) cnt++;
        else break;
    }
    if (cnt <= (m-1)/2) cout << cnt << endl;
    else cout << m-cnt << endl;

}

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

int main (){
  string S, T;
  int A, B;
  string U;
  cin >> S >> T >> A >> B >> U;

  if (S == U) {
    --A;
  } else {
    --B;
  }
  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<string, string> P;
const ll MOD = 1000000007LL;
int a[100000];
int cnt1[100001], cnt2[100001];
int L[100010], R[100010];
int main() {
	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0) cnt1[a[i]]++;
		else cnt2[a[i]]++;
	}
	for (int i = 2; i <= 100000; i++) L[i] = max(cnt2[i], L[i - 1]);
	for (int i = 99999; i >= 1; i--) R[i] = max(cnt2[i], R[i + 1]);
	ll ans = 1LL << 60;
	for (int i = 1; i <= 100000; i++) {
		ans = min(ans, (n / 2 - cnt1[i]) + (n / 2 - max(L[i - 1], R[i + 1])));
	}
	cout << ans << endl;
}

Measured memory_bytes: 2176
#include<iostream>

using namespace std;

int main()
{
  int a,b,c;

  cin >> a >> b >> c;

  if(a==b){
    if(a==c) cout<<"1" << endl;
    else cout << "2" << endl;
  } else if(a==c||b==c){
    cout << "2" << endl;
  } else {
    cout << "3" << endl;
  }

  return 0;
}

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

int N;
vector<long long> x,y;

int solve(){
    if(N == 1)return 1;
    
    int res = N;
    for(int i = 0; i < N;i++){
        for(int j = 0; j < N; j++){
            if(i == j)continue;
            long long dx = x[j] - x[i], dy = y[j] - y[i];
            
            int sub = 0;
            for(int i2 = 0; i2 < N; i2++){
                for(int j2 = 0; j2 < N;j2++){
                    if(j2 == i2)continue;
                    if(dx == x[j2] - x[i2] && dy == y[j2] - y[i2])++sub;
                }
            }
            res = min(res,N-sub);
        }
    }
    return res;
}







int main(){
    cin >> N;
    x.resize(N),y.resize(N);
    for(int i = 0; i < N;i++) cin >> x[i] >> y[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  bool p[n];
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    p[i]=(a==b);
  }
  int cur=0;
  int m=0;
  rep(i,0,n){
    if(p[i]) cur++;
    else cur=0;
    m=max(m,cur);
  }
  if(m>=3) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll a,b,c;
	
	std::cin >> a >>b >> c ;

	if ((a == b) && (b == c)) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using db = double;
using vi = vector<int>;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << #x <<"\t" << x <<endl
const int inf = 0x3f3f3f3f;
const db eps = 1e-8;
const int mod = 1e9+7;
ll qpow(ll a, ll b){
	ll ret = 1;
	while(b){
		if(b&1)ret = ret*a%mod;
		a = a*a%mod;
		b>>=1;
	}
	return ret;
}
int h, w;
char g[110][110];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> h >> w;
	for(int i=1; i<=h; ++i){
		cin >> g[i]+1;
	}
	int dp[110][110];
	memset(dp, 0x3f, sizeof(dp));
	dp[1][1] = g[1][1]=='.'?0:1;
	for(int i=1; i<=h; ++i){
		for(int j=1; j<=w; ++j){
			if(i==1&&j==1)continue;
			dp[i][j] = min(dp[i][j], dp[i-1][j]+(g[i-1][j]=='.'&&g[i][j]=='#'));
			dp[i][j] = min(dp[i][j], dp[i][j-1]+(g[i][j-1]=='.'&&g[i][j]=='#'));
		}
	}
	cout<< dp[h][w];
}





Measured memory_bytes: 384
import java.util.*;
import java.io.*;
class Main {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String str[] = br.readLine().split(" ");
        int num = Integer.parseInt(br.readLine());
        //int height = Integer.parseInt(str[1]);
        String str2[] = br.readLine().split(" ");
        int[] arr = new int[str2.length];
        int temp=0;
        for(int i=0;i<str2.length;i++)
        {
            temp = Integer.parseInt(str2[i]);
            arr[temp-1]=i+1;
        }
        for(int i=0;i<str2.length;i++)
            System.out.print(arr[i]+" ");
   }
}

Measured memory_bytes: 47684
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n, m; cin >> n >> m;
    ll cntr = 0, cntp = 0;
    vector<ll> a(100005, 0);
    REP(i, m){
        ll ind; 
        string s;
        cin >> ind >> s;
        if(s == "WA" && a[ind] != -1){
            a[ind]++;
        }
        else{
            if(a[ind] != -1){
                cntp += a[ind];
                cntr++;
                a[ind] = -1;
            }
        } 
    }
    cout << cntr << " " << cntp << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {


				var inputArray = retreiveLongArray();
				var inputCount = 2;

				// 不正な入力は処理しない
				if (inputArray.Length != inputCount) {
					Console.WriteLine("invalid input");
					return;
				}
				var N = inputArray[0];
				var M = inputArray[1];

				var S = retreiveStringArray()[0].Select(x => x).ToArray();
				var T = retreiveStringArray()[0].Select(x => x).ToArray();

				var L = getLcm(N, M);
				var X = new Dictionary<long, char>();
				for (int i = 0; i < N; i++) {

					var position = i * (L / N);
					if (!X.ContainsKey(position)) {
						X.Add(position, S[i]);
					}

				}

				for (int i = 0; i < M; i++) {

					var position = i * (L / M);
					if (!X.ContainsKey(position)) {
						X.Add(position, T[i]);
					}
					else {
						if (X[position] != T[i]) {
							Console.WriteLine(-1);
							return;
						}
					}

				}
				//答えの出力
				var ans = L;
				Console.WriteLine(ans);

			}

			/// <summary>
			/// スペースで区切られた文字列配列の入力を受け取る
			/// </summary>
			/// <returns></returns>
			private static string[] retreiveStringArray() {
				var inputArray = Console.ReadLine().Split(' ');
				return inputArray;
			}

			/// <summary>
			/// スペースで区切られた整数配列の入力を受け取る
			/// </summary>
			/// <returns></returns>
			private static long[] retreiveLongArray() {
				var inputArray = Console.ReadLine().Split(' ');
				var longArray = inputArray.Select(s => long.Parse(s));
				return longArray.ToArray();
			}


			/// <summary>
			/// 2組みずつの入力データ(数値)からTuppleListを作成する
			/// </summary>
			/// <param name="N"></param>
			/// <returns></returns>
			private static List<Tuple<long, long>> createLongTuppleList(long N) {
				var inpList = new List<Tuple<long, long>>();

				for (int i = 0; i < N; i++) {
					var inp = retreiveLongArray();
					var item1 = inp[0];
					var item2 = inp[1];
					inpList.Add(new Tuple<long, long>(item1, item2));
				}
				return inpList;
			}

			/// <summary>
			/// 最小公倍数を返す
			/// </summary>
			/// <param name="a"></param>
			/// <param name="b"></param>
			/// <returns></returns>
			private static long getLcm(long a, long b) {
				return (a * b / getGcd(a, b));
			}

			/// <summary>
			/// 最大公約数
			/// </summary>
			/// <param name="a"></param>
			/// <param name="b"></param>
			/// <returns></returns>
			private static long getGcd(long a, long b) {
				if (a < b) {
					return getGcd(b, a);
				}
				if (b > 0) {
					return getGcd(b, a % b);
				}
				else {
					return a;
				}
			}
	}
}

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

signed main() {
  int n, d, x; cin >> n >> d >> x;
  int cnt = x;

  for(int i = 0; i < n; i++) {
    int a; cin >> a;
    int tmp = (d-1)/a + 1;
    cnt += tmp;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
H,W = map(int, input().split())
GRID = []
for _ in range(H):
    ws = list(input())
    GRID.append(ws)

dp = []
for _ in range(H):
    row = [0] * W
    dp.append(row)
   
P = 1000000007
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            continue
            
        if GRID[i][j] == '#':
            continue

        v = 0
        # up
        if i-1 >= 0:
            v = (v + dp[i-1][j]) % P
        # left
        if j-1 >= 0:
            v = (v + dp[i][j-1]) % P

        dp[i][j] = v

# print(dp)
print(dp[H-1][W-1])

Measured memory_bytes: 51428
#include "bits/stdc++.h"
using namespace std;

int main(){
    long long A,B,K;
    cin >> A >> B >> K;

    if(K<A) cout << A-K << ' '<< B<<endl;
    else if(A<=K && K<A+B) cout << 0 << ' ' << (A+B)-K <<endl;
    else cout << 0 << ' ' << 0 <<endl;
}


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


#ifdef A
int main(void)
{
	int a, b;
	cin >> a >> b;
	if (a == b)
		cout << "a == b" << endl;
	else if (a < b)
		cout << "a < b" << endl;
	else
		cout << "a > b" << endl;

	return 0;
}
#endif
#ifdef B
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b && b < c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}
#endif
#ifdef C
int main()
{
	vector<int> arr(3);
	for (vector<int>::iterator  i = arr.begin(), e = arr.end(); i != e; ++i)
	{
		cin >> *i;
	}
	sort(arr.begin(), arr.end());

	for (vector<int>::iterator i = arr.begin(), e = arr.end(); i != e; ++i)
	{
		cout << *i << " ";
	}
	cout << endl;
	return 0;
}
#endif
#ifdef D
int main()
{
	int W, H, x, y, r;
	const string yes("Yes"), No("No");
	bool is = true;
	cin >> W >> H >> x >> y >> r;

	// x????????????check
	if (r>x || (x + r)> W) {
		is = false;
	}
	if (r > y || (y + r) > H) {
		is = false;
	}

	if (is)
		cout << yes << endl;
	else
		cout << No << endl;


	return 0;
}
#endif

Measured memory_bytes: 3180
from collections import deque

def bfs():
    visit = [0] * (n + 1)
    e = [0] * (m + 1)
    x = [0] * (n + 1)
    q = deque()
    for i in range(1, n + 1):
        if not visit[i]:
            q.append(i)
            visit[i] = 1
            while q:
                j = q.popleft()
                for g in G[j]:
                    if not e[g[2]]:
                        #print(e, visit, q, x, j)
                        e[g[2]] = 1
                        if not visit[g[0]]:
                            x[g[0]] = g[1] + x[j]
                            visit[g[0]] = 1
                            q.append(g[0])
                        else:
                            #print(x[g[0]], g[1] + x[j])
                            if not x[g[0]] == g[1] + x[j]:
                                return False
    return True

n, m = map(int, input().split())
G = [[] for _ in range(n + 1)]
for i in range(m):
    l, r, d = map(int, input().split())
    G[l].append([r, d, i])
    G[r].append([l, -d, i])
print("Yes" if bfs() else "No")

Measured memory_bytes: 90228
#include<stdio.h>
#define INFTY (1<<21)
int main(){
	int n,c[100]={},m[100][100],d[100],p[100],i,j,u,a,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&a);
			m[i][j]=a==-1?INFTY:a;
		}
	}
	for(i=0;i<n;i++){
		d[i]=INFTY;
		p[i]=0;
	}
	p[0]=-1;
	d[0]=0;
	c[0]=1;
	while(1){
		int minv=INFTY;
		u=-1;
		for(i=0;i<n;i++){
			if(minv>d[i]&&c[i]!=2){
				minv=d[i];
				u=i;
			}
		}
		if(u==-1)break;
		c[u]=2;
		for(i=0;i<n;i++){
			if(c[i]!=2&&m[u][i]!=INFTY){
				if(d[i]>m[u][i]){
					d[i]=m[u][i];
					p[i]=u;
					c[i]=1;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		if(p[i]!=-1){
			sum+=m[i][p[i]];
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1068