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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

int main()
{
    int n,m;
    scanf(" %d %d", &n, &m);

    UF uf(n+m);

    rep(i,n)
    {
        int k;
        scanf(" %d", &k);
        rep(j,k)
        {
            int L;
            scanf(" %d", &L);
            --L;
            uf.unite(i,n+L);
        }
    }

    string ans="YES";
    rep(i,n) if(!uf.same(0,i)) ans="NO";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <stdint.h>	// require uint64_t

using namespace std;

int main()
{
	int price[][7] = { 
			{   0, 300, 500, 600, 700,1350,1650 },
			{   0,   0, 350, 450, 600,1150,1500 },
			{   0,   0,   0, 250, 400,1000,1350 },
			{   0,   0,   0,   0, 250, 850,1300 },
			{   0,   0,   0,   0,   0, 600,1150 },
			{   0,   0,   0,   0,   0,   0, 500 },
			{   0,   0,   0,   0,   0,   0,   0 } };
	int dist[][7] = {
			{   0,   0,   0,   0,   0,   0,   0 },
			{   6,   0,   0,   0,   0,   0,   0 },
			{  13,   7,   0,   0,   0,   0,   0 },
			{  18,  12,   5,   0,   0,   0,   0 },
			{  23,  17,  10,   5,   0,   0,   0 },
			{  43,  37,  30,  25,  20,   0,   0 },
			{  58,  52,  45,  40,  35,  15,   0 } };

	for (int i = 0; i < 7; ++i ){
		for (int j = 0; j < 7; ++j ){
			if (i != j ){
				if (price[i][j] == 0 ){
						price[i][j] = price[j][i];
				} // end if
				if (dist[i][j] == 0 ){
					dist[i][j] = dist[j][i];
				} // end if
			} // end if
		} // en for
	} // end for  
			 
		
//	cut here before submit 
//	freopen ("testcase.highwaytoll", "r", stdin );
	int from;

	while (cin >> from && from ){
		int fromh, fromm;
		cin >> fromh >> fromm;
		int to,toh, tom;
		cin >> to >> toh >> tom;
		from--;to--;
		int res = 0;
		int em = fromh*60 + fromm;
		int dm = toh*60 + tom;

		// ツ環暗クツ妥篠湘崢づ個篠楪甘板妥堕づづ債づ按つ「
//		if (em < 17*60 + 30 && dm > 19*60 + 30 ){
		if ( (17*60 + 30 <= em && em <= 19*60 + 30 ) 
		||   (17*60 + 30 <= dm && dm <= 19*60 + 30 ) ){ 
			int d = dist[from][to];
			if (d > 40 ){
				res = price[from][to];
			}else{
				res = (price[from][to]/2 + 49)/50*50;
			} // end if
 		}else{
				res = price[from][to];
		} // end if
		cout << res << endl;	

	} // end loop

		
	return 0;
}

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

namespace ConsoleApp69 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = st[0];
            int M = st[1];
            string[] A = new string[N];
            string[] B = new string[M];

            for (int i = 0; i < N; i++) {
                A[i] = Console.ReadLine();
            }
            for (int i = 0; i < M; i++) {
                B[i] = Console.ReadLine();
            }

            bool flg = true;

            for (int i = 0; i <= N - M; i++) {
                
                for (int j = 0; j <= N - M; j++) {
                    flg = true;

                    //チェック工程
                    for (int k = 0; k < M; k++) {
                        for (int l = 0; l < M; l++) {
                            if (A[i + k][j + l] != B[k][l]) {
                                //チェック工程を抜ける
                                k = M;
                                l = M;
                                flg = false;
                            }
                        }
                    }

                    if (flg) {
                        Console.WriteLine("Yes");
                        return;
                    }

                }
            }

            Console.WriteLine("No");

        }
    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;
#define ll long long

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+')ans++;
		else ans--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int chain(int x,int y);

char mas[8][8];

int main(){
  int n;
  int x,y;
  cin >> n;
  for(int p = 0;p < n;p++){

    for(int i = 0;i < 8;i++){
      for(int j = 0;j < 8;j++){
	cin >> mas[i][j];
      }
    }
    
    cin >> x >> y;
    x--;y--;
    mas[y][x] = '0';
    for(int i = 1;i <= 3;i++){
      if(x + i <= 7){
	if(mas[y][x + i] == '1'){
	  mas[y][x + i] = '0';
	  chain(x + i,y);
	}
      }
      if(y + i <= 7){
	if(mas[y + i][x] == '1'){
	  mas[y + i][x] = '0';
	  chain(x,y + i);
	}
      }
      if(x - i >= 0){
	if(mas[y][x - i] == '1'){
	  mas[y][x - i] = '0';
	  chain(x - i,y);
	}
      }
      if(y - i >= 0){
	if(mas[y - i][x] == '1'){
	  mas[y - i][x] = '0';
	  chain(x,y - i);
	}
      }
    }
    cout << "Data" << " " << p + 1 << ":" << endl;
    for(int i = 0;i < 8;i++){
      for(int j = 0;j < 8;j++){
	cout << mas[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

int chain(int x,int y){
  for(int i = 1;i <= 3;i++){
    if(x + i <= 7){
      if(mas[y][x + i] == '1'){
	mas[y][x + i] = '0';
	chain(x + i,y);
      }
    }
    if(y + i <= 7){
      if(mas[y + i][x] == '1'){
	mas[y + i][x] = '0';
	chain(x,y + i);
      }
    }
    if(x - i >= 0){
      if(mas[y][x - i] == '1'){
	mas[y][x - i] = '0';
	chain(x - i,y);
      }
    }
    if(y - i >= 0){
      if(mas[y - i][x] == '1'){
	mas[y - i][x] = '0';
	chain(x,y - i);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
long long x[100003];
int main()
{
    long long i,n,k,g;
    cin>>n>>k;
    if(n==1)
    {
        cin>>g;
        if(g==k) cout<<"POSSIBLE\n";
        else cout<<"IMPOSSIBLE\n";
        return 0;
    }
    cin>>x[0]>>x[1];
    g=__gcd(x[0],x[1]);
    for(i=2;i<n;++i)
    {
        cin>>x[i];
        g=__gcd(x[i],g);
    }
    for(i=0;i<n;++i)
    {
        if(x[i]>=k)
        {
            if((x[i]-k)%g==0)
            {
                cout<<"POSSIBLE\n";
                return 0;
            }
        }
    }
    cout<<"IMPOSSIBLE\n";
}


Measured memory_bytes: 1024
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
  int a,b;
  cin >>a>>b;
  if(a%2==1&&b%2==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;
    cin>>S;

    if(n<3200)cout<<"red\n";
    else cout<<S<<"\n";

    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
int getInt(){
    int s;
    scanf("%d", &s);
    return s;
}
int main(){
    int n;
    cin >> n;
    int x[n];
    REP(i, n) x[i] = getInt();

    int sum = 0;
    REP(i, n) sum += x[i];

    int ave1, ave2, ave3;
    ave1 = sum / n;
    ave2 = ave1 - 1;
    ave3 = ave1 + 1;

    int ans1 = 0;
    int ans2 = 0;
    int ans3 = 0;
    REP(i, n){
        ans1 += (x[i] - ave1) * (x[i] - ave1);
        ans2 += (x[i] - ave2) * (x[i] - ave2);
        ans3 += (x[i] - ave3) * (x[i] - ave3);
    }
    int ans = 0;
    ans = min(ans1, ans2);
    ans = min(ans, ans3);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = stdIn.nextInt();
		}
		
		int m = stdIn.nextInt();
		int num[] = new int[n + m];
		for(int i = 0; i < n + m; i++){
		    if(i < n){
		        num[i] = a[i];
		    }else{
		        num[i] = stdIn.nextInt();
		    }
		}
		
		Arrays.sort(num);
        
        for(int i = 0; i < n + m; i++){
            if(i == 0){
                if(num[i] != num[i + 1]){
                    System.out.println(num[i]);
                }
            }else if(i == n + m - 1){
                if(num[i - 1] != num[i]){
                    System.out.println(num[i]);
                }
            }else{
                if(num[i - 1] != num[i] && num[i] != num[i + 1]){
                    System.out.println(num[i]);
                }
            }
            
        }
        
		stdIn.close();
	}

}




Measured memory_bytes: 165980
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
multiset<int>s;int n,m;
typedef multiset<int>::iterator IT;
int main(){
	scanf("%d",&n);
	for(R int i=1,x;i<=n;++i)scanf("%d",&x),s.insert(x);
	IT it;
	scanf("%d",&m);
	for(R int i=1,x;i<=m;++i){
		scanf("%d",&x);
		it=s.lower_bound(x);
		if(it==s.end()||(*it)!=x)return puts("NO"),0;
		s.erase(it);
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[][] a=new int[s[0]][];
		int[] h=new int[s[0]];
		int l=(s[2]/s[1])*2,p=0,g=0;
		long[] ans=new long[s[0]+1];
		s[2]%=s[1];
		a[0]=sc.Ia;
		ans[0]=(a[0][0]+(a[0][1]==1?s[2]:-s[2])+s[1])%s[1];
		g=(int)ans[0];
		for(int i = 1;i<s[0];i++) {
			a[i]=sc.Ia;
			ans[i]=(a[i][0]+(a[i][1]==1?s[2]:-s[2])+s[1])%s[1];
			if(a[0][1]!=a[i][1]){
				if(a[0][1]==1&&(s[1]+a[i][0]-a[0][0])%s[1]<=s[2]*2){p++;}
				else if(a[0][1]==2&&(s[1]+a[0][0]-a[i][0])%s[1]<=s[2]*2){p++;}
				if(a[0][1]==1&&((s[1]+a[i][0]-a[0][0])%s[1])+s[1]<=s[2]*2){p++;}
				else if(a[0][1]==2&&((s[1]+a[0][0]-a[i][0])%s[1])+s[1]<=s[2]*2){p++;}
				p=(p+l)%s[0];
			}
		}
		ans[s[0]]=long.MaxValue;
		Array.Sort(ans);
		if(a[0][1]==2){p=s[0]-p;}
		for(int i = 0;i<s[0];i++) {
			if(ans[i]==g){g=i;break;}
		}
		if(ans[g]==ans[g+1]&&a[0][1]==1){g++;}
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<s[0];i++) {sb.Append(ans[(i+g-p+s[0])%s[0]]+"\n");}
		Console.Write(sb);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

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

typedef long long ll;

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

    int n,factorial=1;
    cin >> n;
    double sum = 0;
    vector<double> x(n),y(n),v(n);
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
        v[i] = i + 1;
    }
    do{
        for(int i=0;i<n-1;i++){
            sum += sqrt(((x[v[i]-1])-(x[v[i+1]-1]))*((x[v[i]-1])-(x[v[i+1]-1]))
                        +((y[v[i]-1])-(y[v[i+1]-1]))*((y[v[i]-1])-(y[v[i+1]-1])));
        }
    }while(next_permutation(v.begin(),v.end()));
    for(int i=2;i<=n;i++) factorial *= i;
    printf("%.10lf\n",sum/factorial);
    return 0;
}

Measured memory_bytes: 256
x, k ,d = map(int, input().split())
x = abs(x)
move  = x // d
if move > k:
    print(x - k * d)
else:
    rest = x - move * d
    if (k-move)%2 == 0:
        print(rest)
    else:
        print(abs(rest-d))

Measured memory_bytes: 9176
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] a_asArgs)
        {
			int[] l_aiN = Console.ReadLine().ToCharArray().Select(a => a - '0').ToArray();

			for (int l_iIndex = 1; l_iIndex < l_aiN.Length; l_iIndex++)
			{
				if (l_aiN[l_iIndex] != 9)
				{
					Console.WriteLine(l_aiN[0] - 1 + (l_aiN.Length - 1) * 9);
					return;
				}
			}
			Console.WriteLine(l_aiN.Sum());
		}
	}
}


Measured memory_bytes: 13396
Scanf.scanf "%d %d %d %d" (fun a b c d ->
    let rec loop taka aoki turn =
        if turn then (
            let aoki = aoki - b in
            if aoki > 0 then loop taka aoki false else "Yes"
        ) else (
            let taka = taka - d in
            if taka > 0 then loop taka aoki true else "No"
        )
    in
    print_endline @@ loop a c true
)

Measured memory_bytes: 3724
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, m;

    cin >> n >> m;

    vector<map<ll, ll>> a(n + 1);
    vector<P> ans(m + 1);

    for (int i = 0; i < m; i++)
    {
        ll p, y;

        cin >> p >> y;
        a[p].insert(make_pair(y, i + 1));
    }

    for (int i = 1; i <= n; i++)
    {
        int j = 1;
        for (auto x : a[i])
        {
            ans[x.second] = P(i, j);
            j++;
        }
    }

    for (int i = 1; i <= m; i++)
    {
        string x, y;

        x = to_string(ans[i].first);
        y = to_string(ans[i].second);

        while (x.size() < 6)
        {
            x.insert(x.begin(), '0');
        }

        while (y.size() < 6)
        {
            y.insert(y.begin(), '0');
        }

        cout << x + y << endl;
    }
}


Measured memory_bytes: 14080
import java.util.Arrays;
import java.util.Scanner;

public class Main 
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n;
		long sum=0,x;
		n=sc.nextInt();
		x=sc.nextLong();
		int arr[] = new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		for(int i=0;i<n;i++)
		{
			sum=sum+arr[i];
		}
		Arrays.sort(arr);
		int k=0;
		int flag=0;
		/*for(int i=0;i<n;i++)
			System.out.println(arr[i]);
		System.out.println(sum);*/
		if(sum==x)
			System.out.println(n);
		else if(sum<x)
		{
			System.out.println(n-1);
		}	
		else
		{
			while(true)
			{
				if(arr[k]<=x)
				{
					x=x-arr[k];
					k++;
					flag=1;
				}
				else
					break;
			}
			if(flag==0)
				System.out.println(0);
			else
				System.out.println(k);
		}
	}
}


Measured memory_bytes: 22996
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.IntMap as M

readIntLL :: IO [[Int]]
readIntLL = map(unfoldr(B.readInt.B.dropWhile(==' '))).B.lines<$>B.getContents

rsort :: Ord a => [a] -> [a]
rsort = sortBy$flip compare

main=do
    n:as <- readIntLL
    print $ maximum $ map snd $ M.toList
        $ foldl' (\m k -> M.insertWith (+) (k-1) 1 $ M.insertWith (+) (k+1) 1 $ M.insertWith (+) k 1 m) M.empty
        $ head as


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

class State {
public:
  int cost;
  int dir;
  int x;
  int y;
  State(int cost, int dir, int x, int y) : cost(cost), dir(dir), x(x), y(y) {}
  bool operator <(const State &s) const {
    if(cost != s.cost) return cost > s.cost;
    if(x != s.x) return x > s.x;
    if(y != s.y) return y > s.y;
    if(dir != s.dir) return dir > s.dir;
    return false;
  }
};

int main() {
  while(1) {
    int w, h;
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    int data[h][w];
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	cin >> data[i][j];
      }
    }

    int c[4];
    for(int i = 0; i < 4; i++) {
      cin >> c[i];
    }

    int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
    priority_queue<State> PQ;
    PQ.push(State(0, 0, 0, 0));
    set<State> visited;
    while(!PQ.empty()) {
      State s = PQ.top();
      PQ.pop();
      if(visited.find(s) != visited.end()) continue;
      visited.insert(s);
      if(s.x == w-1 && s.y == h-1) {
	cout << s.cost << endl;
	break;
      }
      for(int i = 0; i < 4; i++) {
	int dir;
	switch(i) {
	case 0: dir = s.dir;break;
	case 1: dir = (s.dir+1)%4;break;
	case 2: dir = (s.dir+2)%4;break;
	case 3: dir = (s.dir+3)%4;break;
	}
	int nx = s.x + d[dir][0];
	int ny = s.y + d[dir][1];
	if(nx < 0 || nx >= w) continue;
	if(ny < 0 || ny >= h) continue;
	PQ.push(State(s.cost+c[i], dir, nx, ny));
      }
      int dir;
      if(data[s.y][s.x] != 4) {
	switch(data[s.y][s.x]) {
	case 0: dir = s.dir;break;
	case 1: dir = (s.dir+1)%4;break;
	case 2: dir = (s.dir+2)%4;break;
	case 3: dir = (s.dir+3)%4;break;
	}
	int nx = s.x + d[dir][0];
	int ny = s.y + d[dir][1];
	if(nx < 0 || nx >= w) continue;
	if(ny < 0 || ny >= h) continue;
	PQ.push(State(s.cost, dir, nx, ny));
      }
    }
  }
  return 0;
}

Measured memory_bytes: 10000
def number_sort(a, b, c):
    arr = [a, b, c]
    arr = sorted(arr)
    print( str(arr[0]) + " " + str(arr[1]) + " " + str(arr[2]) )

if __name__ == "__main__":

    param = input()
    param = param.split(" ")

    a = int(param[0])
    b = int(param[1])
    c = int(param[2])

    number_sort(a, b, c)


Measured memory_bytes: 5600
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_X = 1000000;
const int MAX_Y = 1000000;

/* typedef */

/* global variables */

int x, y;
int rems[MAX_Y];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> x >> y;
    if (x == 0) break;

    for (int i = 0; i < y; i++) rems[i] = -1;

    int rp = 0;

    while (x && rems[x] < 0) {
      rems[x] = rp++;
      x = (x * 10) % y;
    }
    //printf("rp=%d, x=%d, rems[x]=%d\n", rp, x, rems[x]);

    if (x == 0)
      printf("%d 0\n", rp);
    else
      printf("%d %d\n", rems[x], rp - rems[x]);
  }

  return 0;
}

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  int n = sz(s);
  int count = 0;
  rep(i,n/2) {
    if(s[i]!=s[n-1-i]) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


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

	cout << (N / 2) + (N % 2) << endl;
}

Measured memory_bytes: 256
/**
 * C - Energy Drink Collector
 * https://atcoder.jp/contests/abc121/tasks/abc121_c
 * 
 * ＜解法＞
 * 計算量：{必ず入力する}
 * ポイント
 * なるべく安い店で多く仕入れるのが原則
 **/
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<long, long>> shops(N);  
    for(int i=0; i<N; i++) {
        long ai, bi;
        cin >> ai >> bi;
        shops[i] = pair<long, long>(ai, bi);
    }
    sort(shops.begin(), shops.end());
    long price = 0;
    long count = M;
    for(auto s:shops) {
        if(count <= s.second) {
            price += s.first*count;
            count = 0;
        } else {
            price += s.first*s.second;
            count -= s.second;
        }
        if(count ==0) {
            break;
        }
    }

    cout << price << endl;


}


Measured memory_bytes: 1920
//Atcoder
#include <bits/stdc++.h>
#define inp "inp"
#define out "out"
#define MOD 1000000007
#define MAGIC 1000
using namespace std;
string s;
long long  D,dp[10005][105][5];
vector <long long > digits;
long long  DP (long long  id,long long  summod,long long  tight){
    if (id == -1) return (summod == 0) ? 1 : 0;
    if (dp[id][summod][tight] != -1 && tight == 0) return dp[id][summod][tight];
    long long  zz = 9;
    if (tight == 1) zz = digits[id];
    long long  res = 0;
    for (long long  i = 0; i <= zz; i++){
        long long  newTight = 0;
        if (i == digits[id]) newTight = tight;
        res += DP(id-1,(summod + i) % D,newTight);
        res = (res + MOD) % MOD;
    }
    if(tight == 0) dp[id][summod][tight] = res;
    return res;
}
main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    cin >> s;
    cin >> D;
    if (s == "0") cout << 0;
    memset(dp,-1,sizeof(dp));
    for (long long  i = s.size()-1; i >= 0; i--) digits.push_back(s[i]-48);
    long long ans = DP(digits.size()-1,0,1) - 1;
    if (ans == -1 ) cout << MOD - 1;
    else cout << (ans + MOD)%MOD;
}


Measured memory_bytes: 42240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        String str = st.nextToken();

        if("s".equals(str.substring(str.length()-1, str.length()))) {
            pw.println(str + "es");
        } else {
            pw.println(str + "s");
        }

        br.close();
        pw.close();
    }
}

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

int main() {
  int64_t x;
  cin >> x;
  int64_t y = 100;
  int i;
  for (i = 0; x > y; i++) {
    y = y * (1 + 0.01);
}
  cout << i << endl;
}


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

int main(){
    int a, b;
    int d, r;
    double f;

    cin >> a >> b;

    d = a / b;
    r = a% b;
    f = double(a)/double(b);

    printf("%d %d %.5f",d,r,f);

    return(0);
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i = 0;i < N; i++){
    cin >> A.at(i);
  }
  
  int min;
  while(true){

    sort(A.begin(), A.end());
    
    int M = A.at(N-1);
    for ( int i = 0; i < N; i++){
      if ( M > A.at(i) && A.at(i) != 0){
        M = A.at(i);
      }
    }
    
    int a = count(A.begin(), A.end(), 0);
    int b = count(A.begin(), A.end(), M);
    if(a + b == N){
      min = M;
      break;
    }else{
      for (int i = 0; i < N; i++){
        if(A.at(i) != 0 && A.at(i) != M){
          A.at(i) = A.at(i) % M;
        }
      }
    }
  }
  
  cout << min << endl;
  return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define ll long long int
#define P pair
#define pll pair<long long, long long>
#define pii pair<int, int>
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define enl '\n'
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
int main(){
    int n ; 
    cin >> n ;
    int arr[n] , a;
    init(arr,0);
    int o = 0 ;
    for(int i = 0 ; i <n ; i++){
        cin >> a;
        if(i == 0) o = a ;
        arr[a]++;
    }
    if(o != 0){
        cout << 0;
        return 0;
    }
    ll ans = 1; 
    if(arr[0] != 1){
        cout << 0 ; 
        return 0;
    }
    for(int i  = 2 ; i< n ; i++){
        ans *=  power(arr[i-1],arr[i],998244353);
        ans %= 998244353; 
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string>s(h);
    vector<vector<int>>x(h,vector<int>(w,-1));
    vector<vector<int>>y(h,vector<int>(w,-1));
    rep(i,h)cin>>s[i];
    int ans=0;
    rep(i,h){
        int cnt=0;
        rep(j,w){
            if(s[i][j]=='.'){cnt++; x[i][j]=cnt;}
            if(s[i][j]=='#')cnt=0;
        }
    }
    rep(i,h){
        for(int j=w-2; j>=0; --j){
            if(s[i][j]=='.'&&s[i][j+1]=='.')x[i][j]=x[i][j+1];
        }
    }
    rep(i,w){
        int cnt=0;
        rep(j,h){
            if(s[j][i]=='.'){cnt++; y[j][i]=cnt;}
            if(s[j][i]=='#')cnt=0;
        }
    }
    rep(i,w){
        for(int j=h-2; j>=0; --j){
            if(s[j][i]=='.'&&s[j+1][i]=='.')y[j][i]=y[j+1][i];
        }
    }
    rep(i,h)rep(j,w){
        ans=max(ans,x[i][j]+y[i][j]-1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 37760
#include <bits/stdc++.h> 
     
    using namespace std; 
    #define ll long long
    #define ld long double
   ll gcd(ll a,ll b)
   {
    if(b==0)
        return a;
    return gcd(b,a%b);
   }
    int main()
    {
        ll n;
        cin >> n;
        string s;
        cin >> s;
        // ll cur=0;
        // ll prev=0;
        // ll nm1=0;
        // ll nm2=0;
        // ll pdif=0;
        // ll pct=0;
        // ll ans=0;
        // for(ll i=0;i<n;i++)
        // {
        //     if(s[i]=='W')
        //         cur++;
        //     if(s[i]=='R')
        //     {
        //         if(cur>0)
        //         {
        //             nm1++;
        //             ll dif=cur-prev;
        //             if(dif>0)
        //             {
        //                 nm2+=dif;
        //                 pdif=dif;
        //                 pct=1;
        //             }
        //             if(dif==0)
        //             {
        //                 pct+=1;
        //             }
        //             prev=cur;
        //             //nm2+=dif;
        //             //out << nm1 << nm2;
        //         }
        //     }
        // }
        // nm2=nm2-pdif;
        // if()
        // if(nm1<=nm2)
        //     cout << nm1 << "\n";
        // else
        //     cout << nm2 << "\n";
        ll rprew[n];
        ll rprer[n];
        ll rcr=0;
        ll rcw=0;
        for(ll i=n-1;i>=0;i--)
        {
            if(s[i]=='R')
                rcr=rcr+1;
            if(s[i]=='W')
                rcw=rcw+1;
            rprer[i]=rcr;
            rprew[i]=rcw;
        }
        ll crr=0;
        ll crw=0;
        ll ans=0;
        for(ll i=0;i<n-1;i++)
        {
            if(s[i]=='R')
                crr++;
            if(s[i]=='W')
                crw++;
            if(crw==rprer[i+1])
                ans=crw;
        }
        cout << ans << "\n";
    }
    

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int p[n],ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>p[i];
		if (p[i]!=i+1)
		{
			++ans;
		}
	}
	if (ans<=2)
	{
		cout<<"YES\n";
	}
	else
	{
		cout<<"NO\n";
	}
	return 0;
}


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

int main(){
	int N;
	cin >> N;
	int A[N],ANS[N];
	for(int i=0;i<N;i++){
		cin >> A[i];
		ANS[A[i]-1]=i+1;
	}
	for(int i=0;i<N;i++){
		cout << " " << ANS[i];
	}
	cout << endl;
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#define TASK_NAME

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void solve() {
    ll n, W;
    cin >> n >> W;
    vector<ll> v(n);
    vector<int> w(n);
    for (int i = 0; i < n; i++)
        cin >> w[i] >> v[i];

    vector<vector<ll> > dp(n+1, vector<ll>(W+1));  // dp[i][j]: i - number of used items, j - storable weight

    for (ll i = 0; i <= n; i++)
        dp[i][0] = 0;
    for (ll i = 0; i <= W; i++)
        dp[0][i] = 0;

    for (ll i = 1; i <= n; i++)
        for (ll j = 1; j <= W; j++)
            if (j >= w[i-1])
                dp[i][j] = max(dp[i-1][j], dp[i-1][j - w[i-1]] + v[i-1]);
            else
                dp[i][j] = dp[i-1][j];

    cout << dp[n][W];
}

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

Measured memory_bytes: 80256
from bisect import bisect_right
A, B, Q = map(int, input().split())
BIG = 10**10 + 1
S = [-BIG] + [int(input()) for _ in range(A)] + [BIG*2]
T = [-BIG] + [int(input()) for _ in range(B)] + [BIG*2]
for _ in range(Q):
  x = int(input())
  shrine_b = bisect_right(S, x)
  dsl = x-S[shrine_b-1]
  dsr = S[shrine_b]-x
  temple_b = bisect_right(T, x)
  dtl = x-T[temple_b-1]
  dtr = T[temple_b]-x

  print(min(
    dsl if dsl > dtl else dtl,
    dsr if dsr > dtr else dtr,
    dsl * 2 + dtr,
    dsl + dtr * 2,
    dsr * 2 + dtl,
    dsr + dtl * 2
  ))

Measured memory_bytes: 14096
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 608;

int a[N], b[N], c[N], n, k;
ll p[N], f[N][N];

inline bool in(int a, int l, int r) {
	return l <= a && a < r;
}

bool chk(int l, int r) {
	for (int i = 0; i < k; i++)
		if (in(a[i], l, r) ^ in(b[i], l, r)) return true;
	return false;
}

int main() {
	scanf("%d%d",&n,&k);
	if (n == 1) {puts("1"); return 0;}
	p[0] = 1;
	for (int i = 0; i < n-k; i++)
		p[i+1] = p[i] * (i<<1|1) %MOD;
	n <<= 1;
	for (int i = 0; i < k; i++) {
		scanf("%d%d",a+i,b+i);
		c[a[i]--] = c[b[i]--] = 1;
	}
	for (int i = 1; i <= n; i++)
		c[i] = (!c[i]) + c[i-1];
	ll ans = 0;
	for (int l = 0; l < n; l++)
		for (int r = l; (r += 2) <= n;) {
			int x = c[r] - c[l];
			if ((x&1) || chk(l, r)) continue;
			ll s = p[x>>1];
			for (int i = l; (i += 2) < r;)
				s = (s - f[l][i] * p[c[r]-c[i]>>1]) %MOD;
			f[l][r] = s;
			ans = (ans + s * p[(n-x>>1)-k]) %MOD;
		}
	if (ans < 0) ans += MOD;
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length();i++) {
		if (i%2==0&&s[i]=='L') {
			cout << "No" << endl;
			return 0;
		}
		else if (i%2==1&&s[i]=='R') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main(){
    int n;
    cin >> n;
    map<string, long long> mp;
    long long ans = 0;
    for (int i = 0; i < n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (mp[s] == 0) mp[s] = 1;
        else {
            long long x = mp[s];
            ans += x;
            mp[s] = x + 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    println!("{}", n * n * n)
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MX 100001
#define FF freopen("input.in","r",stdin); freopen("output.txt","w",stdout);
int n,k;
int a[MX];
int dp[MX];
int f(int i)
{
    if(i==n)return 0;
    if(dp[i]!=-1)return dp[i];
    int ans=1e9;
    for(int z=1;z<=k&&z+i<=n;z++)
    {
        dp[i]=ans=min(ans,f(i+z)+abs(a[i]-a[i+z]));
    }
    return ans;
}
int main()
{
    //FF;
    IOS;
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof dp);
    cout<<f(1);
}



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

int main(){
  string s,t;
  int ans = 0;
  cin >> s >> t;
  rep(i,s.size()){
    if(s.at(i) != t.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	char a;
	cin >> a;
	if (a == 'a' or a == 'i' or a == 'u' or a == 'e' or a == 'o') cout << "vowel" << endl;
	else cout << "consonant" << endl;
}

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

int main(){
  while(true){
    int n, m, t, p;
    cin >> n >> m >> t >> p;

    if(n==0 && m==0 && t==0 && p==0)
      break;

    int Ori[64][64] = { {0} };
    for(int y=0; y<m; y++){
      for(int x=0; x<n; x++){
        Ori[y][x] = 1;
      }
    }

    for(int i=0; i<t; i++){
      int d,c;
      cin >> d >> c;

      if(d==1){
        for(int x=0; x<c; x++){
          for(int y=0; y<m; y++){
            Ori[y][2*c-1-x] += Ori[y][x];
            Ori[y][x] = 0;
          }
        }
        for(int x=0; x<n; x++){
          for(int y=0; y<m; y++){
            Ori[y][x] = Ori[y][x+c];
            Ori[y][x+c] = 0;
          }
        }
      }
      else{
        for(int y=0; y<c; y++){
          for(int x=0; x<n; x++){
            Ori[2*c-1-y][x] += Ori[y][x];
            Ori[y][x] = 0;
          }
        }
        for(int y=0; y<m; y++){
          for(int x=0; x<n; x++){
            Ori[y][x] = Ori[y+c][x];
            Ori[y+c][x] = 0;
          }
        }
      }
    }
    for(int i=0; i<p; i++){
      int x, y;
      cin >> x >> y;

      cout << Ori[y][x] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    string s; cin >> s;
    if(s.size() == 2) cout << s << endl;
    else {
        reverse(all(s));
        cout << s << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int X;
	scanf("%d",&X);

	int ans = 0;
	for(int i = 1; i*i <= X; i++){

		int tmp = i*i;
		while(tmp*i > tmp && tmp*i <= X)tmp *= i;

		ans = max(ans,tmp);
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//______________________________________________________________________________
int main()
{
       speed;
       ll x,k,d;
       cin>>x>>k>>d;
       ll xx = abs(x);
       ll rq = xx%d;
       ll og = (xx-rq)/d;
       if(og <= k){
              ll dff = k-og;
              if((dff%2)==0){cout<<rq<<endl;}
              else{cout<<min(abs(rq+d),abs(rq-d));}
              return 0;
       }
       ll a1 = x+k*d;
       ll a2 = x-k*d;
       cout<<min(abs(a1),abs(a2))<<endl;

}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n;
	cin>>n;
	vector<char> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}

	for(int i=0;i<n;i++){
		if(v[i]=='Y'){
			cout<<"Four"<<endl;
			return 0;
		}
	}

	cout<<"Three"<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  rep(i, 0, n) cin >> v[i];
  sort(v.begin(), v.end());
  rep(i, 0, n) {
    if(x > v[i] && i == n-1) {
      cout << i;
      return 0;
    }
    if(x >= v[i]) {
      x -= v[i];
      if(x == 0) {
        cout << i+1;
        return 0;
      }
    } else {
      cout << i;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans = 0;
    if(n >= b){
        ans = a*(b-1)/b;
    }
    else {
        ans = a*n/b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    
    counter = defaultdict(int)
    for ai in A:
        counter[ai] += 1
    for i in range(1, N + 1):
        print(counter[i])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 37280
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N; cin >> N;
    vl a(N); REP(i, N) cin >> a[i];
    vl sum(N+1, 0); REP(i, N) sum[i+1] = sum[i] + a[i];
    
    vvl dp(N+1, vl(N+1, LINF));
    REP(i, N) dp[i][i+1] = a[i];
    
    FOR(len, 2, N+1){
        REP(l, N-len+1){
            ll r = l+len;
            FOR(c,l,r) dp[l][r] = min(dp[l][r], dp[l][c] + dp[c][r]);
            dp[l][r] += sum[r] - sum[l];
        }
    }
    cout << dp[0][N] - sum[N] << endl;
    return 0;
    return 0;
}


Measured memory_bytes: 1536
/**
*    created: 30.06.2020 17:04:01
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
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;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int t = 1 << k;
    int sum = a + b + c;
    int m = max({a, b, c});
    sum -= m;
    m *= t;
    sum += m;
    cout << sum << endl;
    return 0;
}

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


void solve(std::string S){
    cout << (S[1] == 'B' ? "ARC" : "ABC") << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

const int N=2e5+10;

int n;
int a[N];
int b[N];

int main() {
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++) {
	    int x; cin>>x;
	    a[i]=a[i-1]+x; 
        b[i]=b[i-1]^x;
	}
	
	int l=1; 
	long long sum=0;
	
	for(int i=1;i<=n;i++) {
	    while(a[i]-a[l-1]!=(b[i]^b[l-1])) l++;
	    sum+=i-l+1;
	}
	
	cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 5112
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<math.h>
#include <cstdio>
#include<iomanip>
#include <stdio.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 10e9 + 7;
string s[100010];
int b[5] = {};
signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> s[i];
		if (s[i][0] == 'M')b[0]++;
		else if (s[i][0] == 'A')b[1]++;
		else if (s[i][0] == 'R')b[2]++;
		else if (s[i][0] == 'C')b[3]++;
		else if (s[i][0] == 'H')b[4]++;
	}
	int ans = 0;
	ans += b[0] * b[1] * b[2];
	ans += b[0] * b[1] * b[3];
	ans += b[0] * b[1] * b[4];
	ans += b[0] * b[2] * b[3];
	ans += b[0] * b[2] * b[4];
	ans += b[0] * b[3] * b[4];
	ans += b[1] * b[2] * b[3];
	ans += b[1] * b[2] * b[4];
	ans += b[1] * b[3] * b[4];
	ans += b[2] * b[3] * b[4];
	cout << ans << endl;
}

Measured memory_bytes: 6144