akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	
	vector<ll> a(n+1);
	vector<ll> b(m+1);
	
	rep(i, n+1) {
		if (i == 0) continue;
		ll x;
		cin >> x;
		a[i] = x + a[i - 1];
	}
	
	rep(i, m+1) {
		if (i == 0) continue;
		ll x;
		cin >> x;
		b[i] = x + b[i - 1];
		
	}
	ll ans = 0, best = m;
	rep(i, n + 1){
		if (a[i] > k) break;
		for (ll j = best; j >= 0; j--) {
			if (k >= a[i] + b[j]) {
				best = j;
				ll x = i + j;
				if (ans < x) ans = x;
				break;
			}
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 6424
#include <stdio.h>

int main(){
    int a[3];
    

    scanf("%d%d%d", &a[0], &a[1], &a[2]);

    int i,j, temp;
    for(i=0; i<3; i++){
        for(j=i+1; j<3; j++){
            if (a[i] > a[j]){
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            } 
    }
    }

    printf("%d %d %d\n", a[0], a[1], a[2]);
}



Measured memory_bytes: 2112
using System;

class Program
{
    static void Main(string[] args)
    {
        int a;
        string b;

        a = Int32.Parse(Console.ReadLine());
        b = Console.ReadLine();

        if (b.Length != a)
        {
            return;
        }

        if (a % 2 != 0)
        {
            Console.WriteLine("No");
            return;
        }

        string strHarf = b.Substring(0, a / 2);

        if (b == strHarf + strHarf)
        {
            Console.WriteLine("Yes");
            return;
        }
        else
        {
            Console.WriteLine("No");
            return;
        }
        //int a, b, c;
        //a = int.Parse(Console.ReadLine()); //標準入力
        //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
        //b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
        //c = int.Parse(str[1]);
        //Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
        //    Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
    }
}


Measured memory_bytes: 13140
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n;
    cin>>n;
    cout<<(!n);
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  int ans = int((B - 1) / (A - 1));
  if((B - 1) % (A - 1) != 0) ans += 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods1=998244353;
const int mods2=1e9+7;
const int MAXN=1005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int s[2005][2005];
int gets(int x1,int y1,int x2,int y2) { return s[x2][y2]-s[x1][y2]-s[x2][y1]+s[x1][y1]; }
int main()
{
	int n=read(),k=read();
	for (int i=1;i<=n;i++)
	{
		int x=read(),y=read(); 
		char ch; scanf("%c",&ch);
		if (ch=='W') x+=k;
		s[x%(k*2)+1][y%(k*2)+1]++;
	}
	for (int i=1;i<=k*2;i++)
		for (int j=1;j<=k*2;j++) s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	int ans=0;
	for (int i=1;i<=k;i++)	
		for (int j=1;j<=k;j++)
		{
			int t=gets(0,0,i,j)+gets(i,j,k+i,k+j)+gets(k+i,k+j,k*2,k*2)+gets(0,k+j,i,k*2)+gets(k+i,0,k*2,j);
			upmax(ans,max(t,n-t));
		}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 19412
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end()
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define rep(i, n) for(int i=0;i<(n);++i)
#define repp(i, a, b) for(int i=(a);i<=(b);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

void solve() {
	ll x; cin >> x;
	ll ans = 0;
	ans += x/500*1000;
	x -= x/500*500;
	ans += x/5*5;
	cout << ans;
}
int main() {
	fastio;
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b;
	cin >> a >> b;
	cout << (a + b + 1) / 2 << "\n";

	return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int mx_x=0,x=0;
  for(int i=0;i<s.size();i++){
    if( s.at(i) == 'I' ) x++;
    if( s.at(i) == 'D' ) x--;
    mx_x = max(mx_x,x);
  }
  
  cout << mx_x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	char s[10];
	string s1[100000];
	long long ans=0,ans1=0;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>s[j];
		}
		sort(s,s+10);
		for(int a=0;a<10;a++){
			s1[i]+=s[a];
		}
	}
	sort(s1,s1+n);
	for(int k=0;k<n-1;k++){
		if(s1[k]==s1[k+1]){
			ans1++;
			ans+=ans1;
		}
		else{
			ans1=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7296
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())
    print(X * min(K, N) + Y * max(N - K, 0))


if __name__ == '__main__':
    main()


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray();
            var n = (int)input[0];
            var m = input[1];
            Hoge[] hoges = new Hoge[n];
            for (int i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray();
                hoges[i] = new Hoge {Foo = input[0], Bar = input[1]};
            }

            hoges = hoges.OrderBy(x => x.Foo).ToArray();
            ulong sum = 0;
            ulong count = 0;
            for (int i = 0; i < n; i++)
            {
                if (hoges[i].Bar + count > m)
                {
                    sum += (m - count) * hoges[i].Foo;
                    break;
                }

                sum += hoges[i].Foo * hoges[i].Bar;
                count += hoges[i].Bar;
            }

            Console.WriteLine(sum);
        }

        public class Hoge
        {
            public ulong Foo { get; set; }
            public ulong Bar { get; set; }
        }
    }
}


Measured memory_bytes: 27700
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[55][30];

int main(void){
	          int i,j,k;

	          int n;
	          cin >> n;
	          for(i=1;i<=n;i++){
	        	  string x;
	        	  cin >> x;
	        	  int m=x.size();
	        	  for(j=0;j<m;j++){
	        		  a[i][x[j]-'a']++;
	        	  }
	          }

	          string ans;
	          for(j=0;j<26;j++){
	        	  int c=100;
	        	  for(i=1;i<=n;i++){
	        		  c=min(c,a[i][j]);

	        		  }

        		  if(c!=0){
        			  for(k=1;k<=c;k++)  ans+=(char)(j+'a');

	        	  }
	          }

	          cout << ans << endl;


	          return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <unordered_map>
#include <list>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        string s;cin >> s;
        cout << s[0] << s[1] << s[2];
    }
}

Measured memory_bytes: 3596
#include<cstdio>

int main(){
	int l[10],x,y,i;
	double par;
	while( scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
	,&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&x,&y) != EOF ){
		par=0;
		for(i=0;i<10;i++){
			par+=l[i];
		}
		par = par*x/(x+y);
		for(i=0;par>0;i++){
			par-=l[i];
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 2592
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();

      int[] a = new int[n];
      for(int i = 0; i < n ; i++) {
        a[i] = sc.nextInt();
      }
      
      int cnt = 0;
      boolean flg = false;
      while(true) {
        for(int i = 0; i < n; i++) {
          if(a[i] % 2  != 0) {
            flg = true;
          } else {
            a[i] /= 2;
          }
        }
        if(flg) {
          break;
        }else {
          cnt++;
          flg = false;
        }
      }

      System.out.println(cnt);

	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
int n, p, a, b, c, d;
long long ans, r[MX];
set<int> s;
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", &p);
		r[p-1] = i;
	}
	for(int i = n-1; i >= 0; i--){
		auto t = s.lower_bound(r[i]);
		if(t == s.end()){
			c = d = n;
		}else{
			c = *t;
			t++;
			d = t == s.end() ? n : *t;
			t--;
		}
		if(t == s.begin()){
			a = b = -1;
		}else{
			t--;
			b = *t;
			if(t == s.begin()){
				a = -1;
			}else{
				t--;
				a = *t;
			}
		}
		ans += ((b - a) * (c - r[i]) + (d - c) * (r[i] - b)) * (i+1);
		s.insert(r[i]);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 5760
#include <cstdio>
#include <cstring>
using namespace std;

#define mx 1000006
int A[mx];
bool seen[mx];

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

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

    for(int i=0;i<n;i++) scanf("%d",A+i);
    memset(seen,0,sizeof(seen));

    bool seen_twice=false;

    for(int i=0;i<n;i++){
        if(seen_twice) break;
        int e=A[i];

        for(int f=2;f*f<=e;f++){
            if(e%f==0){
                if(seen[f]){
                    seen_twice=true;
                    break;
                }
                seen[f]=true;
                while(e%f==0) e/=f;
            }
        }

        if(e>1){
            if(seen[e]){
                seen_twice=true;
            }
            seen[e]=true;
        }
    }

    if(!seen_twice){
        printf("pairwise coprime\n");
        return 0;
    }

    int g=A[0];
    for(int i=1;i<n;i++) g=gcd(g,A[i]);

    if(g==1){
        printf("setwise coprime\n");
        return 0;
    }

    printf("not coprime\n");
}


Measured memory_bytes: 6480
import Control.Monad
import Data.List

solve [x, y, z] = if x^2 + y^2 == z^2 then "YES" else "NO"

main = do
    n <- readLn :: IO Int
    rawDataSets <- replicateM n getLine
    let dataSets = (map (sort . map read . words) $ rawDataSets) :: [[Int]]
        in mapM_ (putStrLn . solve) dataSets

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

const int MAX = 1e6 + 5;
int dp[MAX][2];
char a[MAX];

int main() {
	scanf("%s", a + 1);

	int n = strlen(a + 1);

	dp[0][1] = 1;

	for(int i = 1; i <= n; i++) {
		for(int c = 0; c < 2; c++) {
			dp[i][c] = 1e9;

			for(int d = 0; d < 10; d++) {
				int down = d - c - (a[i] - '0');
				int nc = 0;

				if(down < 0) {
					down += 10;
					nc = 1;
				}

				dp[i][c] = min(dp[i][c], dp[i - 1][nc] + d + down);
			}
		}
	}

	printf("%d\n", dp[n][0]);
	return 0;
}

Measured memory_bytes: 9088
//someshsingh22		
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define loop(i,n) for(int i = 0 ; i < n; i++)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define inp_int(n,arr) int arr[n]; loop(i,n) cin >> arr[i];
#define inp_ll(n,arr) ll arr[n]; loop(i,n) cin >> arr[i];
#define out_int(n,arr) loop(i,n) printf("%d ",arr[i]);
#define out_ll(n,arr) loop(i,n) printf("%lld ",arr[i]); cout << endl;
#define all(c) c.begin(),c.end()
// Snippets : BFS, DFS, edger, ncr, chef, inverse, sieve, lis-d*, mat_d*, pow

typedef long long ll;
typedef pair<int, int> ii; 
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main ()
{
	FAST;
	int n; cin >> n;
	for(int i = 1; i<10; i++)
	{
		for(int j = 1; j<10; j++)
			if(i*j==n)
			{
				cout << "Yes";
				return 0;
			}
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 256
import heapq
n,m=map(int,input().split())
ab=[]
for i in range(m+1):
    ab.append([])
for i in range(n):
    a,b=map(int,input().split())
    if a>m:
        continue
    ab[a].append(b)
h = []
s=0
for i in range(1,m+1):
    for v in ab[i]:
        heapq.heappush(h,-1*v)
    if len(h)>0:
        s+=-1*heapq.heappop(h)
print(s)

Measured memory_bytes: 18376
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<bool> vbool;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<llint> vllint;
typedef vector<vllint> vvllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define coutans rep(i, ans.size())cout << ans[i] << endl;
#define mod (llint)1000000007
#define int_max 2147483647
#define ll_max (llint)9223372036854775807

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aのb乗を求める(1000000007で割った余りやで)
llint modpow(llint a, llint b) {
	if (b == 0)return 1;
	if (b == 1)return a;
	llint tmp = modpow(a, b / 2);
	tmp %= mod;
	tmp = tmp * tmp % mod;
	if (b % 2)return tmp * a % mod;
	else return tmp;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= mod;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, mod);
		ans %= mod;
	}
	return ans;
}


int main() {
	int a;
	cin >> a;
	if (a > 999) {
		cout << "ABD" << endl;
	}
	else cout << "ABC" << endl;
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	int ans = 1000;
	rep(i, s.size() - 2) {
		int si = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		ans = min(ans, abs(si - 753));
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << (a + b) * h / 2 << '\n';
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)
#define loopj(x,y) for(int j = x;j<(y);j++)


#define nl cout<<"\n";
#define ll long long int
using namespace std;
#define mod  1000000007


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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;

	ll dt = 26;
	int k = 1;

	while (dt < n)
	{
		n -= dt;
		dt *= 26;
		k++;
	}
	n--;

	string ans;
	loopj(0, k)
	{

		ans += char('a' + n % 26);
		n /= 26;
	}

	reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}

Measured memory_bytes: 3648
/**
 * Created by hiramekun at 23:05 on 2019-10-29.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    double a, b, x;
    cin >> a >> b >> x;
    if (x < a * a * b / 2) {
        cout << fixed << setprecision(10) << atan2(a * b * b, 2 * x) * 180 / M_PI << '\n';
    } else {
        cout << fixed << setprecision(10) << atan2(2 * (a * a * b - x), a * a * a) * 180 / M_PI
             << '\n';
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n, m;
vector<int> g[N], tg[N];

bool read () {
	if (scanf("%d%d", &n, &m) != 2)
		return false;
	forn(i, n)
		g[i].clear();
	forn(i, m){
		int x, y;
		scanf("%d%d", &x, &y);
		--x, --y;
		g[x].pb(y);
	}
	return true;
}

vector<int> ord;
bool used[N];

void ts(int v){
	used[v] = true;
	for (auto u : g[v]) if (!used[u])
		ts(u);
	ord.pb(v);
}

int dp[N];

void solve() {
	ord.clear();
	memset(used, 0, sizeof(used));
	forn(i, n) if (!used[i]) ts(i);
	memset(dp, 0, sizeof(dp));
	forn(i, n){
		int v = ord[i];
		for (auto u : g[v])
			dp[v] = max(dp[v], dp[u] + 1);
	}
	printf("%d\n", *max_element(dp, dp + n));
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N, K;
  cin >> N >> K;
  vector<PLL> xs(N);
  REP(i,N){
	cin >> xs[i];
  }

  LL lb = 0, ub = 2e18;
  while(ub-lb > 1){
	LL m = (lb + ub) / 2;
	LL sum = 0;
	REP(i,N){
	  if(xs[i].FF <= m)
		sum += (m - xs[i].FF) / xs[i].SS + 1;
	}
	if(sum < K) lb = m;
	else ub = m;
  }
  cout << lb+1 << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
ll lcm(ll x,ll y){
    ll g=gcd(x,y);
    ll xb=x/g,yb=y/g;
    return xb*yb*g;
}
int main(void){
    ll n;cin>>n;
    vector<ll> t(n);
    rep(i,n) cin>>t[i];
    sort(t.begin(),t.end());
    ll l=t[0];
    rep(i,n) l=lcm(l,t[i]);
    cout<<l<<endl;
}


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

int main(){
  string S; cin>>S;
  int sz=S.size();
  int even=0,odd=0;
  for(int i=0;i<sz;i++){
    if(S[i]=='0'){
      if(i%2)
        even++;
      else
        odd++;
    }else{
      if(i%2)
        odd++;
      else
        even++;
    }
  }
  cout<<min(even,odd)<<endl;
}

Measured memory_bytes: 512
s=str(input())
cnt=0
temp=[]
temp2=[]
nagasa=len(s)
lis=[]
cnt2=0
for p in s:
    lis.append(p)

if nagasa%2==0:
    for i in range(nagasa//2):
        temp.append("1")
        temp.append("0")
    for i in range(nagasa//2):
        temp2.append("0")
        temp2.append("1")
    
    for i in range(nagasa):
        if lis[i]!=temp[i]:
            cnt+=1
        elif lis[i]!=temp2[i]:
            cnt2+=1
        
else:
    for i in range(nagasa//2):
        temp.append("1")
        temp.append("0")
    temp.append("1")
    for i in range(nagasa//2):
        temp2.append("0")
        temp2.append("1")
    temp2.append("0")
    
    for i in range(nagasa):
        if lis[i]!=temp[i]:
            cnt+=1
        elif lis[i]!=temp2[i]:
            cnt2+=1
    

print(min(cnt,cnt2))

Measured memory_bytes: 5628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;

class Main {

	static List<List<Edge>> graph;
	static int vNum;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		 graph = new  ArrayList<>();
		vNum = n;
		List<Edge> edgelist = new ArrayList<>();
		for (int j = 0; j < n; j++) {
			String[] str = br.readLine().split(" ");
			edgelist = new ArrayList<>();
			for (int k = 1; k <=n; k++) {
				if(Integer.parseInt(str[k]) != -1){
				edgelist.add(new Edge(k-1, Integer.parseInt(str[k])));
				}
			}
			graph.add(edgelist);
		}

		System.out.println(prim());
	}

	static class Edge implements Comparable<Edge> {
		int to;
		int cost;

		public Edge(int to, int cost) {
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Edge o) {
			// TODO ?????????????????????????????????????????????
			return this.cost - o.cost;
		}
	}

	static int prim() {
		int total = 0;
		Queue<Edge> que = new PriorityQueue<Edge>();
		que.offer(new Edge(0, 0));
		boolean[] use = new boolean[vNum];
		while (!que.isEmpty()) {
			Edge e = que.poll();
			if (use[e.to]) {
				continue;
			}
			use[e.to] = true;
			total += e.cost;
			for (Edge e2 : graph.get(e.to)) {
				que.offer(e2);
			}
		}
		return total;
	}

}

Measured memory_bytes: 28196
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    ll cnt = 0, x;
    rep(i,1,n+1){
    	cin >> x;
    	if(i&1 and x&1)	cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3492
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
// const long long mod=998244353;
// const long long inf=mod*mod;
// const long long d2=(mod+1)/2;
long long mod;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<4110;i++){
		if(i*8/100==a&&i*10/100==b){
			printf("%d\n",i);return 0;
		}
	}
	printf("-1\n");

}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
int Judge(char *);
int Judge(char *s)
{
    int cnt=0,flag=0;
    for(;*s!='\0';s++)
    {
        if(*s=='C')
        {
            cnt++;
        }
        if(*s=='F'&&cnt>0)
        {
            flag=1;
        }
    }
    return flag;
}
int main()
{
    char a[101];
    int r;
    scanf("%s",a);
    r=Judge(a);
    if(r==1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3
1
---+/

void main(string[] args) {
  const A = readln.chomp.to!long;
  const B = readln.chomp.to!long;

  [1, 2, 3].filter!(x => x != A && x != B).front.writeln;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_f

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define minf INT_MIN
#define pb push_back
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<<" "; cout<<"\n";
#define printn(v) for(auto x:v) cout<<x<<"\n";
#define F first
#define S second
#define mp make_pair

int dp[1000][1000];

int32_t main() {
	fastio;
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char ch; cin >> ch;
			if (ch == '.') dp[i][j] = 1;
			else dp[i][j] = 0;
		}
	}
	for (int i = 0; i < w; i++) {
		if (dp[0][i] != 0) continue;
		for (int j = i + 1; j < w; j++) dp[0][j] = 0;
		break;
	}
	for (int i = 0; i < h; i++) {
		if (dp[i][0] != 0) continue;
		for (int j = i + 1; j < h; j++) dp[j][0] = 0;
		break;
	}
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (dp[i][j] == 0) continue;
			dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;
		}
	}
	cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 7508
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
    int N;
    cin >> N;
    vector<ll> v, w;
    rep(i, 0, N) {
        ll x, y;
        cin >> x >> y;
        v.pb(x+y);
        w.pb(x-y);
    }
    sort(all(v));
    sort(all(w));
    ans = max(abs(v[sz(v)-1] - v[0]), abs(w[sz(w)-1]-w[0]));
    
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 6560
s = str(input())
k = int(input())

len_s=len(s)
ss=s+s
sss=s+s+s
#print(sss)
len_ss=len(ss)
len_sss=len(sss)
ans=0

if len(set(sss))==1:
	ans=k*len_s//2
		


else:
	if k==1:
		for i in range(len_s-1):
			if s[i]==s[i+1]:
				ans=ans+1
				s=list(s)
				s[i+1]="0"
				s="".join(s)
	if k==2:
		for i in range(len_ss-1):
			if ss[i]==ss[i+1]:
				ans=ans+1
				ss=list(ss)
				ss[i+1]="0"
				iss="".join(ss)
			
	if k>=3:
		for i in range(len_sss-1):
			if sss[i]==sss[i+1]:
				ans=ans+1
				sss=list(sss)
				sss[i+1]="0"
				sss="".join(sss)
		
		
		if ans%3==0:
				ans=ans/3*k
				
		else:
				ans=ans//3*k+k-1
	



print(int(ans))
	

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int N,W;
ll w,v,wmin;
vector<ll> va[4];


int main(){
  scanf("%d %d", &N,&W);
  REP(i,4) va[i].push_back(0);
  REP(i,N){
    int w,v;
    scanf("%d %d",&w,&v);
    if(i==0) wmin = w;
    va[w-wmin].push_back(v);
  }
  REP(i,4){
    sort(va[i].begin()+1,va[i].end(),greater<ll>());
  }
  REP(i,4){
    for(int j = 1;j<va[i].size()+1;j++){
      va[i][j] += va[i][j-1];
    }
  }
  ll sum = 0;
  REP(i,va[0].size())REP(j,va[1].size())REP(k,va[2].size())REP(l,va[3].size()){
    ll W_sum = i*wmin + j*(wmin+1) + k*(wmin+2) + l*(wmin+3);
    if(W < W_sum) continue;
    sum = max(sum, va[0][i] + va[1][j] + va[2][k] + va[3][l]);
  }
  printf("%lld\n",sum);
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    print(S[:3])


if __name__ == '__main__':
    main()


Measured memory_bytes: 37436
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using ll = long long;
using namespace std;

int main() {
    int n, m, c = 0;
    cin >> n >> m;
    int v[n][n];
    fill_n(*v, n*n, 0);
    vector<int> V(n);
    iota(V.begin(), V.end(), 0);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        v[a-1][b-1] = 1; v[b-1][a-1] = 1;
    }
    do {
        int f = 1;
        for (int i = 0; i < n-1; ++i) {
            if(!v[V[i]][V[i+1]]) {f = 0; break;}
        }
        c += f;
    } while (next_permutation(V.begin()+1, V.end()));
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int, C: int, D: int):
    ret = max(A * B, C * D)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}

void solve(long long A, long long B, long long C){
    cout<<min(C,B/A)<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
}


Measured memory_bytes: 256
n=int(input())
a=[list(input()) for i in range(n)]
alpha=[0]*26
for aa in a:
    for x in range(26):
        if chr(ord("a")+x) in aa:
            alpha[x]+=1
ans=""
for x,i in enumerate(alpha):
    if i==n:
        mini=51
        for aa in a:
            cnt=aa.count(chr(ord("a")+x))
            mini=min(mini,cnt)
        ans+=(chr(ord("a")+x))*mini
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  cin>>n;
  double ans=0.00000;
  for(int i=0;i<n;i++){
    cin>>a;
    ans+=1.0/a;
  }
  
  ans=1/ans;
  
  cout<<ans<<endl;
}
 

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int x[10000], y[10000], i, t, s;

	for (i = 0;; i++)
	{
		scanf("%d %d", &x[i], &y[i]);

		t = i;

		if (x[i] == 0 && y[i] == 0)
			break;
	}
	for (i = 0; i < t; i++)
	{
		if (x[i] < y[i])
		{
			x[i] = x[i];
		}
		else
		{
			if (x[i] > y[i])
			{
				s = x[i];
				x[i] = y[i];
				y[i] = s;
			}
			else
			{
				if (x[i] == y[i])
				{
					x[i] = x[i];
					y[i] = y[i];
				}
			}
		}

		printf("%d %d\n", x[i], y[i]);

	}
	return(0);
}

Measured memory_bytes: 624
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

void print_setprecision(int i, long double rsl) {
  cout << fixed << setprecision(i) << rsl << endl;
}

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

  int n;
  ll k;
  cin >> n >> k;
  map<int, int> a;
  rep(i, 1, n + 1) {
    int _a;
    cin >> _a;
    a[i] = _a;
  }

  int tmp = 0;
  int cur = 1;
  bool isReached[n + 1];
  rep(i, 1, n + 1) isReached[i] = false;
  isReached[cur] = true;
  while(true) {
    cur = a[cur];
    if(isReached[cur]) {
      ++tmp;
      if(tmp == k) {
        cout << cur << endl;
        return 0;
      }
      break;
    }
    ++tmp;
    if(tmp == k) {
      cout << cur << endl;
      return 0;
    }
    isReached[cur] = true;
  }
  int tmp2 = 0;
  rep(i, 1, n + 1) isReached[i] = false;
  isReached[cur] = true;
  map<int, int> m;
  m[0] = cur;
  while(true) {
    cur = a[cur];
    if(isReached[cur]) {
      ++tmp2;
      m[tmp2] = cur;
      break;
    }
    ++tmp2;
    m[tmp2] = cur;
    isReached[cur] = true;
  }

  int x = (k - tmp) % tmp2;
  cout << m[x] << endl;
}


Measured memory_bytes: 19112
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<functional>
#include<iterator>
#include<math.h>

using namespace std;

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

	int a,b,c;
	long long k;
	cin >> a >> b >> c >> k;

	if(k%2==0) cout << a-b << "\n";
	else		cout << b-a << "\n";

	return 0;
}

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


#define MOD 1000000007
#define INF (1ll<<60)
typedef long long ll;
using namespace std;


ll n, k;

int main(){
    cin >> n >> k;
    ll divi = n/k;
    ll cnt = 0;
    if (k % 2 == 0){
        cnt += pow((n+k/2)/k, 3);
    }
    cnt += pow(divi, 3);
    cout << cnt << endl;
}


Measured memory_bytes: 512
n=int(input())
s=input()
p=[]
for i in range(len(s)):
	if ord(s[i])-ord("A")+n>=26:
		q=-26
	else:
		q=0
	p.append(ord(s[i])-ord("A")+q+n)
ans=""
for i in range(len(s)):
	ans+=chr(ord("A")+p[i])
print(ans)


Measured memory_bytes: 40924