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

public class Main
{

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

        int k = 0;
        int best = 0;
        int n = scan.nextInt();

        while (n != 0) {
            for (int i = 0; i < n; i++) {
                int p = scan.nextInt();
                int b = scan.nextInt();
                int c = scan.nextInt();

                if (best <= b + c) {
                    best = b + c;
                    k = p;

                }

            }
            System.out.println(k + " " + best);
            k = 0;
            best = 0;
            n = scan.nextInt();
        }
    }
}



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


int main(){
    std::string b;
    std::cin >> b;
    for (int i = 0;i < (int)b.size(); i++){
        switch (b[i]) {
            case 'A':
                std::cout << 'T';
                break;
            case 'C':
                std::cout << 'G';
                break;
            case 'G':
                std::cout << 'C';
                break;
            case 'T':
                std::cout << 'A';
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N, M, C = map(int,input().split())
B = list(map(int,input().split()))
A = list(list(map(int,input().split()))for i in range(N))
ans = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += A[i][j]*B[j]
    if tmp > -C:
        ans +=1
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	static int[][] dp;
	static String s1, s2;

	static int dp(int l1, int l2) {
		if (l1 == s1.length() || l2 == s2.length())
			return 0;
		if (dp[l1][l2] != -1)
			return dp[l1][l2];
		return dp[l1][l2] = s1.charAt(l1) == s2.charAt(l2) ? 1 + dp(l1 + 1, l2 + 1)
				: Math.max(dp(l1, l2 + 1), dp(l1 + 1, l2));
	}

	static StringBuilder trace(int l1, int l2) {
		StringBuilder ans = new StringBuilder();
		while (l1 < s1.length() && l2 < s2.length()) {
			if (s1.charAt(l1) == s2.charAt(l2)) {
				ans.append(s1.charAt(l1++));

				l2++;
			} else {
				if (l1 < s1.length() - 1 && l2 < s2.length() - 1) {
					if (dp[l1][l2 + 1] < dp[l1 + 1][l2]) {
						l1++;
					} else
						l2++;
				} else if (l1 != s1.length() - 1)
					l1++;
				else if (l2 != s2.length() - 1)
					l2++;
				else break;
			}
		}
		return ans;
	}

	public static void main(String[] args) throws IOException {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		s1 = sc.next();
		s2 = sc.next();
		dp = new int[s1.length()][s2.length()];
		for (int[] x : dp) {
			Arrays.fill(x, -1);
		}
		dp(0, 0);
		pw.println(trace(0, 0));
		pw.flush();
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = Integer.parseInt(next());
			}
			return arr;
		}
	}
}


Measured memory_bytes: 77088
#include<stdio.h>

int main(void){
    int a,b,num[3],i,max=-99999;
    scanf("%d%d",&a,&b);
    num[0]=a+b;
    num[1]=a-b;
    num[2]=a*b;
    for(i=0;i<3;i++){
        if(num[i]>max){
            max=num[i];
        }
    }
    printf("%d\n",max);
    return 0;
}


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

int N, A, B;
int v[300005];

int main() {
	scanf("%d%d%d", &N, &A, &B);

	if (A < (N + B - 1) / B || A > N - B + 1) return printf("-1\n"), 0;

	for (int i = 0; i++ < N; ) v[i] = i;

	A = N - A;

	for (int i = 1; A && i <= N; i += B) {
		A = min(A, N - i);
		if (A >= B - 1) {
			reverse(v+i, v+i+B);
			A -= B - 1;
		} else {
			reverse(v+i, v+i+A+1);
			A = 0;
		}
	}

	for (int i = 0; i++ < N; ) printf("%d ", v[i]);
	printf("\n");
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

  int N,K; cin >> N >> K;

  int mx = (N-1) * (N-2) / 2;
  if(K > mx) {
    cout << -1 << endl;
    return 0;
  }

  vector<P> ans;
  rep(i, N-1) {
    ans.push_back(P(i+1, N));
  }

  int add = mx - K;
  rep(i, N-1) {
    if(add == 0) break;
    for(int j = i+1; j < N-1; ++j) {
      if(add == 0) break;
      ans.push_back(P(i+1, j+1));
      --add;
    }
  }

  int anss = ans.size();
  cout << anss << endl;
  rep(i, anss) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 384
import Control.Monad

perfectPower :: Integer -> [Integer]
perfectPower x = 1 : do
  b <- [2 .. floor $ sqrt $ fromIntegral x]
  p <- [2 .. floor $ sqrt $ fromIntegral x]
  guard (b^p <= x)
  return $ b^p

solve :: Integer -> Integer
solve x = maximum $ filter (<= x) $ perfectPower x

main :: IO ()
main = do
  x <- read <$> getLine
  print . solve $ x


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) {
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << ans;
}



Measured memory_bytes: 3984
using System;
using System.Collections.Generic;
using System.Linq;

namespace Saikoro
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int>();
            int[] men = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var saikoro=new Saikoro(men);
            int n = int.Parse(Console.ReadLine());
            for(int i=0;i<n;i++)
            {
                var q = Console.ReadLine()
                    .Split(' ')
                    .Select(int.Parse)
                    .ToArray();
                list.Add(saikoro.ShowRightSide(q[1], q[0]));

            }
            foreach(int i in list)
            {
                Console.WriteLine(i);
            }
        }
    }
    class Saikoro
    {
        public int[] men { get; set; }

        public Saikoro(int[] men)
        {
            this.men = men;
        }
        public void  showTop()
        {
            Console.WriteLine(men[0]);
        }

        public int ShowRightSide(int front,int top)
        {
            int frontId = SearchId(front);
            int topId = SearchId(top);
            int[,] answer =
            {
                {-1,3,1,4,2,-1 },
                { 2,-1,5,0,-1,3},
                {4,0,-1,-1,5,1 },
                {1,5,-1,-1,0,4 },
                { 3,-1,0,5,-1,2},
                { -1,2,4,1,3,-1},
            };
            return men[answer[frontId, topId]];
        }
        private int SearchId(int num)
        {
            for(int i=0; i < men.Length; i++)
            {
                if (num == men[i])
                {
                    return i;
                }
            }
            return -1;
        }

        public void Move(char c)
        {
            switch (c)
            {
                case 'N':
                    N();
                    break;
                case 'S':
                    S();
                    break;
                case 'E':
                    E();
                    break;
                case 'W':
                    W();
                    break;
                default:
                    break;
            }
        }
        public void N()
        {
            var temp = (int[])men.Clone();
            men[0] = temp[1];
            men[1] = temp[5];
            men[5] = temp[4];
            men[4] = temp[0];
        }
        public void W()
        {
            var temp =(int[]) men.Clone();
            men[0] = temp[2];
            men[2] = temp[5];
            men[5] = temp[3];
            men[3] = temp[0];
        }
        public void E()
        {
            var temp = (int[])men.Clone();
            men[2] = temp[0];
            men[5] = temp[2];
            men[3] = temp[5];
            men[0] = temp[3];
        }
        public void S()
        {
            var temp = (int[])men.Clone();
            men[0] = temp[4];
            men[4] = temp[5];
            men[5] = temp[1];
            men[1] = temp[0];

        }
    }
}



Measured memory_bytes: 18440
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int n;
int main()
{
	fast;
	cin>>n;
	cout<<"ABC"<<n<<endl;
	return 0;
}

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

const int cnnMaxAry = 1000033;

long long fnStrToLL(string sKey)
{
  int nElm;
  int nBase = 1;
  long long nKey = 0;
  for (int i = sKey.size() - 1; i >= 0; i--)
  {
    switch (sKey[i])
    {
      case  'A': nElm = 1;
                 break;
      case  'C': nElm = 2;
                 break;
      case  'G': nElm = 3;
                 break;
      case  'T': nElm = 4;
                 break;
      default:   nElm = 0;
    }
    nKey += nBase * nElm;
    nBase *= 5;
  }
  return nKey;
}

int fnHash1(long long nKey) { return (nKey % cnnMaxAry); }
int fnHash2(long long nKey) { return (1 + (nKey % (cnnMaxAry - 1))); }

void fnDic(string stasDic[])
{
  int nCmdCnt;
  cin >> nCmdCnt;

  for (int i = 0; i < nCmdCnt; i++)
  {
    string sCmd;
    string sKey;
    cin >> sCmd >> sKey;

    long long nKey = fnStrToLL(sKey);
    int nCnt = 0;
    for (nCnt = 0; ;nCnt++)
    {
      int ix = (fnHash1(nKey) + nCnt * fnHash2(nKey)) % cnnMaxAry;
      if (stasDic[ix] == sKey)
      {
        if (sCmd[0] == 'i')
          break;
        else if (sCmd[0] == 'f')
        {
          cout << "yes" << endl;
          break;
        }
      }
      else if (stasDic[ix].size() == 0)
      {
        if (sCmd[0] == 'i')
        {
          stasDic[ix] = sKey;
          break;
        }
        else if (sCmd[0] == 'f')
        {
          cout << "no" << endl;
          break;
        }
      }
    }
  }
}

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

  static string stasDic[cnnMaxAry];
  fnDic(stasDic);
  
  return 0;
}

Measured memory_bytes: 21948
/**
 * Program name:Insert Sort
 * author:Xin Peng
 * date:2020/1/5
 * Pragram problem source: AOJ
*/
#include <iostream>
using namespace std;

#define MAX 100

/**
 * @brief Trace display
 * @param data Data to display
 * @param length Length of the data
*/
void trace(int data[], int length)
{
    for (int i = 0; i < length; i++)
    {
        cout << data[i];
        if (i != length - 1)
        {
            cout << " ";
        }
    }
    cout << endl;
}

// Insert Sort
void InsertSort(int data[], int length, bool ascent, void (*traceHandler)(int data[], int length))
{
    int tmpValue;

    for (int i = 1; i < length; i++)
    {
        tmpValue = data[i];
        int j = i - 1;

        if (ascent)
        {
            while (j >= 0 && data[j] > tmpValue)
            {
                data[j + 1] = data[j];
                j--;
            }
        }
        else
        {
            while (j >= 0 && data[j] < tmpValue)
            {
                data[j + 1] = data[j];
                j--;
            }
        }
        data[j + 1] = tmpValue;

        if (traceHandler)
        {
            traceHandler(data, length);
        }
    }
}

int main()
{
    int n;
    int R[MAX];

    cin >> n;

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

    trace(R,n);
    InsertSort(R, n, true, trace);

    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int ll;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  int a, b;
  cin >> a >> b;

  int x = b * 10;
  // cout << x << endl;
  for (int i = x; i < x + 10; i++) {
    // cout << (int)(i * 0.08) << endl;
    if ((int)(i * 0.08) == a) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

using namespace std;

struct Item {
	int value, weight;
};

int N, W;
Item items[NMAX+1];
int C[NMAX+1][WMAX+1], G[NMAX+1][WMAX+1];

void compute(int &maxValue, vector<int> &selection){
	for (int w = 0; w <= W; w++) {
		C[0][w] = 0;
		G[0][w] = DIAGONAL;
	}

	for (int i = 1; i <= N; ++i) C[i][0] = 0;

	for (int i = 1; i <= N; ++i) {
		for (int w = 1; w <= W; ++w) {
			C[i][w] = C[i-1][w];
			G[i][w] = TOP;
			if (items[i].weight > w) continue;
			if (items[i].value + C[i-1][w-items[i].weight] > C[i-1][w]) {
				C[i][w] = items[i].value + C[i-1][w-items[i].weight];
				G[i][w] = DIAGONAL;
			}
		}
	}

	maxValue = C[N][W];
	selection.clear();
	for (int i = N, w = W; i >= 1; i--) {
		if (G[i][w] == DIAGONAL) {
			selection.push_back(i);
			w -= items[i].weight;
		}
	}

	reverse(selection.begin(), selection.end());
}

void input(){
	cin >> N >> W;
	for (int i = 1; i <= N; ++i) {
		cin >> items[i].value >> items[i].weight;
	}
}

int main(int argc, char const *argv[])
{
	int maxValue;
	vector<int> selection;
	input();
	compute(maxValue, selection);

	cout << maxValue << endl;

	return 0;
}


Measured memory_bytes: 11068
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    Int N;
    cin>>N;
    if(N == 0) break;

    vector<vector<Int> >A(30);
    for(Int i=0;i<N;i++){
      Int num;
      cin>>num;
      for(Int j=0;j<num;j++){
        Int d;
        cin>>d; d--;
        A[d].push_back(i);
      }
    }

    vector<Int> key(N);
    for(Int i=0;i<N;i++) key[i] = 1LL<<i;

    Int ans = -1;
    for(Int i=0;i<30;i++){
      Int nkey = 0;
      for(Int j:A[i]) nkey |= key[j];
      for(Int j:A[i]) key[j] = nkey;
      if(nkey == (1LL<<N)-1){ans = i+1; break;}
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3128
/*  
     author : masaow    
     g++ : 17.3.20  
*/        
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;  
/*  
    time : 10 : 14    
    date : 24.02.2020
*/   
// int L,R,mid,target,idx ;
int tests() 
{
    string s ;
    cin >> s ;
    sort(all(s));
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
        return cout << "Yes\n",0;
    cout << "No\n" ; 
    return 0; 
}
int main(){
    I__O ;  
    int cases = 1 ; 
    //cin >> cases;  
    while(cases--)
      tests(); 
  return 0 ; 
}

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

using namespace std;

int n, ans[100005], a[100005], d[100005];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int res = 0;
	for (int i = 1; i <= n + 1; i++) { d[i] = abs(a[i] - a[i - 1]); res += d[i]; }
	for (int i = 1; i <= n; i++) ans[i] = res;
	for (int i = 1; i <= n; i++) 
	{
		int num = abs(a[i + 1] - a[i - 1]);
		ans[i] = ans[i] - d[i] - d[i + 1] + num;
	}
	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <string.h>

int main(void)
{
	int x,y,z,a=0,b,c;
	scanf("%d %d %d",&x,&y,&z);
	while(a < z)
	{
		if(x%2) x--;
		c = x/2;
		x/=2;
		y+=c;
		a++;
		if (a >= z) break;
		if (y%2) y--;
		c = y/2;
		y/=2;
		x+=c;
		a++;
	}
	printf("%d %d",x,y);
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

string str[2000];

int main(){
	while(true){
		int n;
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> str[i];
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < str[i].size() - 1; j++){
				if(str[i][j] == '.' and str[i][j + 1] != '.'){
					for(int k = i; k >= 0; k--){
						if(str[k][j] == '.'){
							str[k][j] = '|';
						}else{
							break;
						}
					}
				}
			}
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < str[i].size() - 1; j++){
				if(str[i][j] == '|' and str[i][j + 1] >= 'a' and str[i][j + 1] <= 'z'){
					str[i][j] = '+';
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < str[i].size(); j++){
				if(str[i][j] == '.'){
					str[i][j] = ' ';
				}
			}
			cout << str[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,K,d,A;
    cin >> N >> K;
    vector<int> data;
    for (int i=0;i<K;i++) {
        cin >> d;
        for (int j=0;j<d;j++) {
            cin >> A;
            data.push_back(A);
        }
    }
    
    int ans=N;
    for (int i=0;i<N;i++) {
    for (int j=0;j<data.size();j++) {
        if(data[j]==i+1) {
            ans--;
            break;
        }
    }
    }
    cout << ans << endl;
    
}


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

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 1;i<n;i++)
	{
		if(s.substr(0,n/2-i)==s.substr(n/2-i,n/2-i))
		{
			cout<<s.substr(0,n-i*2).size()<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#単一始点最短経路問題
#負の辺があっても動作する

#最短経路を求める
#計算量O(N * M)

INF = 10 ** 15
#入力
N, M = map(int, input().split())

# 入力は1-index
# 内部で0-indexにして処理
G = []
for _ in range(M): #M個の辺の情報を受け取る
    l, r, s = map(int, input().split()) #lからrへ重みsの辺が存在
    G += [[l-1, r-1, -s]] #有向グラフのときはここだけ


#メイン文
d = [INF] * N #最短距離を記録しておくリスト
prev = [-1] * N

#最短経路復元
def restore(g): #gまでの最短経路を復元
    path = []
    g -= 1 #0-indexに直す
    path.append(g)
    g = prev[g]
    count = 0
    while g != -1:
        # print ('C')
        path.append(g)
        g = prev[g]
        count += 1
        if count == N + 2:
            break
    path.reverse()
    return path

def shortest_path(s): #S番目の頂点から各頂点への最短距離を求める
    s -= 1
    for i in range(N):
        d[i] = INF
    d[s] = 0
    count = 0
    while True:
        if count == N:
            # print ('B')
            path = restore(N)
            # print (prev)
            # print (path)
            update = False
            for i in range(M): #無向グラフのときは辺は実質的には2倍
                e = G[i]
                if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
                    d[e[1]] = d[e[0]] + e[2]
                    if e[1] in path:
                        return False
                    update = True
                    prev[e[1]] = e[0]
            return True

        count += 1
        # print ('A')
        update = False
        for i in range(M): #無向グラフのときは辺は実質的には2倍
            e = G[i]
            if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                update = True
                prev[e[1]] = e[0]
        if not update:
            return True

#呼び出しスタート地点を入れる
if shortest_path(1):
    print (-d[N - 1])
else:
    print ('inf')

# print (d)

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {

	ll N;
	cin >> N;

	vector<ll> a(N + 1);
	repn(i, N) cin >> a[i];

	map<ll, ll> mp;

	repn(i, N) { mp[a[i]]++; }

	ll ans = 0;

	for (auto itr : mp) {
		ll x = itr.first;
		ll y = itr.second;
		if (y >= x) { ans += y - x; }
		else { ans += y; }
	}

	cout << ans;

	system("PAUSE");

	

}


Measured memory_bytes: 7288
#include <iostream>

using namespace std;

int main()
{
  int x,ans = 0,b = 1;

  cin >> x;

  for(int i = 1;i < 40;i++){
    b = i;
    for(int j = 0;j < 40;j++){
      b *= i;
    if(ans < b && b <= x)
      ans = b;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,i,j,k,n,m,t;
string s[1005];

int main(){
	scanf("%lld%lld",&a,&b);
	if(a!=1&&b!=1)
		printf("1\n");
	else if(a!=2&&b!=2)
		printf("2\n");
	else
		printf("3\n");
	return 0;
}


Measured memory_bytes: 256
function main(arg) {
    // 処理
  arg = Number(arg)
  if (arg < 1200) {
      console.log('ABC')
  } else if (arg < 2800) {
    console.log('ARC')
} else {
    console.log('AGC')
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){

	int H,W,i,j;

	while(1){
		cin >> H >> W;

		if((H==0)&&(W==0))break;
		else{
			for(i=1;i<=H;i++){
				for(j=1;j<=W;j++){
					if(((j%2==1)&&(i%2==1))||((j%2==0)&&(i%2==0)))cout << "#";
					else cout << ".";
				}cout << endl;
			}cout << endl;

			
		}

	}		
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const LL INF=1e18;
struct node{
	LL d; int u,w;
	node() { }
	node(LL _d,int _u,int _w) { d=_d; u=_u; w=_w; }
	bool operator < (const node &b) const
	{
		return d>b.d;
	}
};
struct edge{
	int v,a,b;
	edge( ) { }
	edge(int _v,int _a,int _b) { v=_v; a=_a; b=_b; }
};
vector<struct edge> e[55];
LL dis[55][2505]; int c[55]; int dd[55];
int main(void)
{
	int n,m,s; scanf("%d%d%d",&n,&m,&s); s=min(s,2500);
	for(int i=1;i<=m;i++)
	{
		int u,v,a,b; scanf("%d%d%d%d",&u,&v,&a,&b);
		e[u].push_back(edge(v,a,b));
		e[v].push_back(edge(u,a,b));
	}
	for(int i=1;i<=n;i++) scanf("%d%d",&c[i],&dd[i]);
	for(int i=1;i<=n;i++) for(int j=0;j<=2500;j++) dis[i][j]=INF;
	dis[1][s]=0;
	priority_queue<struct node> q;
	q.push(node(dis[1][s],1,s));
	while(!q.empty())
	{
		struct node TT=q.top(); q.pop();
		LL d=TT.d; int u=TT.u; int w=TT.w;
		if(d>dis[u][w]) continue;
//		printf("d==%lld,u==%d,w==%d\n",d,u,w);
		
		for(auto EE:e[u])
		{
			int v=EE.v; int a=EE.a; int b=EE.b;
			if(w>=a&&dis[v][w-a]>d+b)	
			{
				dis[v][w-a]=d+b;
				q.push(node(dis[v][w-a],v,w-a));
			}
		}
		int nw=min(2500,w+c[u]);
		if(dis[u][nw]>d+dd[u])
		{
			dis[u][nw]=d+dd[u];
			q.push(node(dis[u][nw],u,nw));
		}
	}
	for(int i=2;i<=n;i++)
	{
		LL res=INF;
		for(int j=0;j<=2500;j++) res=min(res,dis[i][j]);
		printf("%lld\n",res);
	}
	return 0;
}

Measured memory_bytes: 6344
N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
y = sorted([list(map(int, input().split())) for _ in range(N)])

cnt = 0
for c, d in y:
  for a, b in x:
    if a < c and b < d:
      x.remove([a, b])
      cnt += 1
      break

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>

#define REP(i, n) for(int i=0;i<n;i++)

using namespace std;

typedef long long ll;


ll n, l;


int main() {

//    ifstream in("/Users/koichihasegawa/src/repository/cpp/AtCoder/ABC/abc130/input.txt");
//    cin.rdbuf(in.rdbuf());

    cin >> n >> l;


    ll min = 1000000000;
    ll ans = 0;
    ll sum = 0;

    REP(i, n) {
        ll taste = l + i;
        sum += taste;
        if (min > abs(taste)) {
            min = abs(taste);
            ans = taste;
        }

    }


    cout << sum - ans;


    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define LL long long
using namespace std;
int n,a[N+5],b[N+5],p[N+5],q[N+5];
struct Data
{
	int p,v;I Data(CI x=0,CI y=0):p(x),v(y){}
	I bool operator < (Con Data& o) Con {return v<o.v;}
}s[2*N+5];
int main()
{
	RI i;LL A=0,B=0;for(scanf("%d",&n),i=1;i<=n;++i)
		scanf("%d%d",a+i,b+i),s[i]=Data(i,a[i]),s[n+i]=Data(n+i,b[i]),A+=a[i],B+=b[i];
	for(sort(s+1,s+2*n+1),i=1;i<=2*n;++i) s[i].p<=n?p[s[i].p]=i:q[s[i].p-n]=i;
	LL ans=min(A,B),t=0,g;for(i=1;i<=n;++i) t+=s[i].v;
	for(i=1;i<=n;++i) p[i]>q[i]&&(swap(p[i],q[i]),0),g=t,
		p[i]<=n&&(g+=s[n+1].v-s[p[i]].v),q[i]<=n+1&&(g+=s[n+2].v-s[q[i]].v),ans=min(ans,g);
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 6900
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s, ans = "Good";
	cin >> s;
	for (int i = 0; i < 3; i++){
		int j = i + 1;
		if (s[i] == s[j]){
			ans = "Bad";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll b(n - 1);
    REP(i, n - 1) cin >> b[i];
    ll res = b[0] + b[n - 2];
    REP(i, n - 2){
        res += min(b[i], b[i + 1]);
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int>answer(n);
  for(int i=0;i<n;i++) answer[i]=1;
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++) {
      int a;
      cin>>a;
      answer[a-1]=0;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++) ans+=answer[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

char s[60][30], buf[2];
int d[60][30][60][30][2];
struct st {
	int lx, ly, rx, ry, c, b;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int C(char c) {
	if (isdigit(c))return c - '0';
	return 0;
}
int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		memset(d, 0x3f, sizeof(d));
		priority_queue<st>que;
		rep(i, h)rep(j, w) {
			scanf("%s", buf); s[i][j] = buf[0];
		}
		rep(j, w) {
			int i = h - 1;
			if (s[i][j] == 'S') {
				for (int k = -2; k <= 2; k++) {
					int a = 3 - abs(k);
					for (int t = 1; t <= a; t++) {
						int nx = i + k, ny = j + t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							d[i][j][nx][ny][0] = C(s[nx][ny]);
							que.push({ i,j,nx,ny,C(s[nx][ny]),0 });
						}
						nx = i + k, ny = j - t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							d[nx][ny][i][j][1] = C(s[nx][ny]);
							que.push({ nx,ny,i,j,C(s[nx][ny]),1 });
						}
					}
				}
			}
		}
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.lx][p.ly][p.rx][p.ry][p.b] != p.c)continue;
			for (int k = -2; k <= 2; k++) {
				int a = 3 - abs(k);
				for (int t = 1; t <= a; t++) {
					if (p.b) {
						int nx = p.lx + k, ny = p.ly + t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							int&u = d[p.lx][p.ly][nx][ny][!p.b];
							int c = p.c + C(s[nx][ny]);
							if (u > c) {
								u = c; que.push({ p.lx,p.ly,nx,ny,u,!p.b });
							}
						}
					}
					else {
						int nx = p.rx + k, ny = p.ry - t;
						if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
							int&u = d[nx][ny][p.rx][p.ry][!p.b];
							int c = p.c + C(s[nx][ny]);
							if (u > c) {
								u = c; que.push({ nx,ny,p.rx,p.ry,u,!p.b });
							}
						}
					}
				}
			}
		}
		int Min = INF;
		rep(i, h)rep(j, w)rep(k, h)rep(t, w)rep(y, 2) {
			if (s[i][j] == 'T' || s[k][t] == 'T')Min = min(Min, d[i][j][k][t][y]);
		}
		if (Min == INF)puts("-1");
		else printf("%d\n", Min);
	}
}

Measured memory_bytes: 28604
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int N;	cin >> N;
	int num = N;
	int sum = 0;
	while (num) {
		sum += num % 10;
		num /= 10;
	}
	if (N%sum == 0) {
		cout << "Yes" << endl;
		cin >> N;
		return 0;
	}
	cout << "No" << endl;
	cin >> N;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	int n;
	cin>>n;
	int a=100000;
	for(int i=0;i<n;i++){
        a*=1.05;
        if(a%1000!=0)a-=a%1000,a+=1000;
	}
    cout<<a<<endl;

	return 0;
}

Measured memory_bytes: 1160
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int A,B,C,X,Y;

    private void solve() {
        A = nextInt();
        B = nextInt();
        C = nextInt();
        X = nextInt();
        Y = nextInt();

        int min = Math.min(X,Y);
        int max = Math.max(X,Y);
        long ans = Long.MAX_VALUE;

        long x = min * C * 2 + A * (X - min) + B * (Y - min);
        long y = max * C * 2;
        long z = A * X + B * Y;

        ans = Math.min(Math.min(x,y),z);

        out.println(ans);
    }
    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

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

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

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

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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


Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,mod=998244353;
int n,a[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    ll ans=1;
    for(int i=1;i<=n;i++)
        ans=ans*__gcd(a[i],i-1)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 640
// ~maqsat~
/*    
**    “Anyone who has never made a mistake has never tried anything new.”
**    © Albert Einstein
*/

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e10 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
    fre("");
    ACCELERATE;
	
	string s;
	cin >> s;

	if(s == "SUN") cout << 7;
	if(s == "MON") cout << 6;
	if(s == "TUE") cout << 5;
	if(s == "WED") cout << 4;
	if(s == "THU") cout << 3;
	if(s == "FRI") cout << 2;
	if(s == "SAT") cout << 1;

    return 0;
}
/*
 
*/


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,k,a,d,cnt,i,j,flg[101]={0};
	scanf("%d %d",&n,&k);
	for(i=0;i<k;i++){
		scanf("%d",&d);
		for(j=0;j<d;j++){
			scanf("%d",&a);
			flg[a]=1;
		}
	}
	for(i=1;i<=n;i++){
		if(flg[i]==0){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

using namespace std;

int main() {

    long long A, B, C, K;
    cin >> A >> B >> C >> K;

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

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
#include <valarray>
// #include <cctype>

#define INF -1

using namespace std;
/*  class   */
class Dice
{
    public:
        void assign();
        void roll(char);
        void roll_W();
        void roll_E();
        void roll_S();
        void roll_N();
        void rotate();
        int top() const;
        int front() const;
        int right() const;
        bool operator==(const Dice & a) const;


    
        vector<int> face;
        // int face[7];
        // string west = "face4", east = "face3",
        //         south = "face2" , north = "face5",
        //         bottom = "face6", top = "face1";
        int W = 4, E = 3, S = 2, N = 5, B = 6, T = 1;
};


int main()
{
    Dice dice1, dice2;

    dice1.assign();
    dice2.assign();

    bool result = false;

    for (int i = 0; i < 4; i++)
    {
        if (dice1 == dice2)
        {
            result = true;
            break;
        }

        dice1.roll_W();

        for (int j = 0; j < 4; j++)
        {
            if (dice1 == dice2)
            {
                result = true;
                break;
            }
            
            dice1.roll_N();

            for (int k = 0; k < 4; k++)
            {
                if (dice1 == dice2)
                {
                    result = true;
                    break;
                }
                
                dice1.rotate();                    
            }
        }
    }

    if (dice1 == dice2)
        cout << "Yes" << endl;    
    else
        cout << "No" << endl;    
}




void Dice::assign()
{
    face.resize(7);
    int i = 0;
    while (i++ < 6)
    {
        cin >> face[i];
    }
    cin.ignore();

}

void Dice::roll(char ch)
{
    if (ch == 'W')
        roll_W();
    else if (ch == 'E')
        roll_E();
    else if (ch == 'S')
        roll_S();
    else
        roll_N();
}


void Dice::roll_W()
{
    int temp = W;
    W = T;
    T = E;
    E = B;
    B = temp;
}

void Dice::roll_E()
{
    int temp = E;
    E = T;
    T = W;
    W = B;
    B = temp;
}

void Dice::roll_S()
{
    int temp = S;
    S = T;
    T = N;
    N = B;
    B = temp;
}

void Dice::roll_N()
{
    int temp = N;
    N = T;
    T = S;
    S = B;
    B = temp;
}

void Dice::rotate()
{
    int temp = S;
    S = W;
    W = N;
    N = E;
    E = temp;            
}

int Dice::top() const
{
    return face[T];
}

int Dice::front() const
{
    return face[S];
}

int Dice::right() const
{
    return face[E];
}


bool Dice::operator==(const Dice & a) const
{

    return (face[W]==a.face[a.W] && 
            face[E]==a.face[a.E] && 
            face[S]==a.face[a.S] && 
            face[N]==a.face[a.N] && 
            face[T]==a.face[a.T] && 
            face[B]==a.face[a.B]);
        
}


Measured memory_bytes: 3096
import sys


def solve(inp):
    (A, B) = map(int, inp.readline().strip().split(' '))

    r = A - B * 2
    if r < 0:
        r = 0

    return str(r)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
struct UnionFind{
  vi par;
  UnionFind(int N) : par(N){
    rep(i, N) par[i] = i;
  }
  int root(int x){
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){
  int n,m;
  cin >> n >> m;
  vi p(n);
  rep(i, n){
    int a;
    cin >> a;
    a--;
    p[i] = a;
  }
  UnionFind tree(n);
  rep(i, m){
    int x,y;
    cin >> x >> y;
    x--; y--;
    tree.unite(x, y);
  }
  int ans = 0;
  rep(i, n){
    if(i == p[i]){
      ans++;
      continue;
    }
    if(tree.same(i, p[i])){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"io"
	"os"
	"strconv"
)

const mod = 1e9 + 7

func main() {
	m := map[byte]int{}
	rd := bufio.NewReader(os.Stdin)
	var (
		by  byte
		err error
	)
	for err != io.EOF {
		by, err = rd.ReadByte()
		m[by]++
	}

	r := 1
	for i := byte('a'); i <= 'z'; i++ {
		r = r * (m[i] + 1) % mod
	}
	os.Stdout.Write([]byte(strconv.Itoa(r-1) + "\n"))
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
#define F first
#define S second
using namespace std;

int n, mxl, mnr=2e9, mlr, ans, mn, b[N], c[N];
pair<int,int> a[N];
int main() {
	int i;
	cin >> n;
	for(i=0; i<n; i++) {
		scanf("%d%d", &a[i].F, &a[i].S);
		a[i].S++;
		mxl = max(mxl, a[i].F);
		mnr = min(mnr, a[i].S);
		mlr = max(mlr, a[i].S - a[i].F);
	}
	ans = mlr + max(0, mnr - mxl);
    sort(a, a+n);
	mxl = 0, mnr = 2e9;
	for(i=0; i<n-1; i++) {
		mxl = max(mxl, a[i].F);
		mnr = min(mnr, a[i].S);
		b[i] = max(0, mnr - mxl);
	}
	mxl = 0, mnr = 2e9;
	for(i=n-1; i>=1; i--) {
		mxl = max(mxl, a[i].F);
		mnr = min(mnr, a[i].S);
		c[i] = max(0, mnr - mxl);
	}
	for(i=0; i<n-1; i++) ans = max(ans, b[i] + c[i+1]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  int n;
  cin >> n;
  vector<int> a(n);
  forn(i,n) cin >> a[i], a[i]--;
  vector<bool> w(n);
  int i = 0;
  int cnt = 0;
  while(!w[i] and i != 1){
    w[i] = 1;
    i = a[i];
    cnt++;
  }
  if (i != 1) cnt = -1;
  cout << cnt;
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

6
1 1
7 1
2 2
6 2
1 3
7 3

 */

Measured memory_bytes: 640
use proconio::marker::Chars;
use proconio::marker::Usize1;
use proconio::{fastout, input};
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        x: usize,
        m: usize,
    }

    let mut ans = x;
    let mut sum = 0;
    let mut cnt = 0;
    let mut init = 0;
    let mut ok: bool = true;
    let mut dp: Vec<usize> = Vec::new();
    for i in 0..m {
        dp.push(ans);
        ans = (ans * ans) % m;
        for j in 0..dp.len() {
            if ans == dp[j] {
                cnt = dp.len() - j;
                init = j;
                ok = false;
                break;
            }
        }
        if ok == false {
            break;
        }
    }
    let mut init_sum = 0;
    for i in 0..init {
        init_sum += dp[i];
    }

    for i in init..dp.len() {
        sum += dp[i];
    }

    let d = (n - init) / cnt;
    let r = (n - init) % cnt;
    sum *= d;
    sum += init_sum;
    for i in 0..r {
        sum += ans;
        ans = (ans * ans) % m;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2336