akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
gpu_hash_table<int, int> mp;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>
 */
using ll = long long;
using ld = long double;
const ll MOD = 924844033;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 1000001;
string s;
int q;
int n;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>s>>q;
    int k;
    while(q--) {
      cin>>k;
      ll res = 0;
      ll d, m, dm;
      d = m = dm = 0;
      owo(i, 0, n) {
        if(i>=k) {
          if(s[i-k]=='D') {
            dm-=m;
            d--;
          }
          if(s[i-k]=='M') {
            m--;
          }
        }
        if(s[i]=='D') {
          d++;
        }
        if(s[i]=='M') {
          m++;
          dm+=d;
        }
        if(s[i]=='C') {
          res+=dm;
        }
        //cout<<d<<" "<<m<<" "<<dm<<" "<<k<<"\n";
      }
      cout<<res<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4316
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scanf("%d %d\n", &n, &x)
	m := make([]int, n)
	for i := range m {
		fmt.Scanf("%d\n", &m[i])
	}
	min_m := 10000
	for _, m_ := range m {
		if m_ < min_m {
			min_m = m_
		}
	}
	for _, m_ := range m {
		x -= m_
	}
	cnt := x / min_m
	fmt.Println(cnt + n)
}

func Lt(a, b []byte) bool {
	la, lb := len(a), len(b)
	l := min(la, lb)
	for i := 0; i < l; i++ {
		if a[i] < b[i] {
			return true
		} else if a[i] > b[i] {
			return false
		}
	}
	if la < lb {
		return true
	}
	return false
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int main()
{
    string left = "qwertasdfgzxcvb";
    string right = "yuiophjklnm";
    string input;
    while(1){
        cin >> input;
        if(input == "#") break;
        int beforehand = 1;
        // nowhand = 0/right, 1/left
        for(int j = 0; j < right.length(); j++){
                if(right[j] == input[0]){
                    beforehand = 0;
                    break;
                }
            }
        int cnt = 0;
        for(int i = 0; i < input.length(); i++){
            int nowhand = 1;
            for(int j = 0; j < right.length(); j++){
                if(right[j] == input[i]){
                    nowhand = 0;
                    break;
                }
            }
            if(beforehand != nowhand){
                cnt++;
                beforehand = nowhand;
            }
        }
        cout << cnt << endl;    
    }
}

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

using namespace std;

int main() {
  int n, source_len, sign_len, count = 0, suffix;
  string source, sign;

  cin >> n >> source;
  source_len = source.length();

  bool success;
  for (int i = 0; i < n; i++) {
	cin >> sign;
	sign_len = sign.length();
	success = false;
	for (int j = 0; j < sign_len; j++) { //先頭文字のループ
	  for (int k = 0; k <= sign_len / 2; k++) { //間隔のループ
		suffix = j;
		for (int l = 0; l < source_len; l++) { //文字のループ
		  if (source[l] != sign[suffix]) {
			break;
		  }
		  if (l == source_len - 1) {
			success = true;
			count++;
			break;
		  }
		  suffix += (k + 1);
		  if (suffix >= sign_len) break;
		}
		if (success) break;
	  }
	  if (success) break;
	}
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 1208
count = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    count[b-1][f-1][r-1] += v

for i in range(4):
    if i > 0:
        print("#"*20)
    for j in range(3):
        for k in range(10):
            print(" " + str(count[i][j][k]), end="")
        print("")



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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var H = input[0];
            var W = input[1];
            var S = new string[H];
            for (int i = 0; i < H; i++) S[i] = Read();
            var ans = 0;
            var x = new int[] { 1, 0, -1, 0 };
            var y = new int[] { 0, 1, 0, -1 };
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (S[i][j] == '#') continue;
                    var cnt = new int[H, W];
                    var que = new Queue<int[]>();
                    que.Enqueue(new int[] { i, j, 0 });
                    cnt[i, j] = -1;
                    while (que.Any())
                    {
                        var chk = que.Dequeue();
                        var h = chk[0];
                        var w = chk[1];
                        var m = chk[2];
                        for (int k = 0; k < 4; k++)
                        {
                            var chkH = h + x[k];
                            var chkW = w + y[k];
                            if (chkH >= 0 && chkH < H && chkW >= 0 && chkW < W)
                            {
                                if (cnt[chkH, chkW] == 0 && S[chkH][chkW] == '.')
                                {
                                    cnt[chkH, chkW] = m + 1;
                                    que.Enqueue(new int[] { chkH, chkW, m + 1 });
                                }
                            }
                        }
                    }
                    for (int k = 0; k < H; k++)
                    {
                        for (int l = 0; l < W; l++)
                        {
                            if (cnt[k, l] > ans) ans = cnt[k, l];
                        }
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

int main(void){
    int n;
    cin >> n;
    while(n>1000)n-= 1000;
    cout << 1000 - n << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef long long ll;

int n;
ll bit[100001];

void add(int a, ll x){
	for(int i=a+1;i<=n;i+=(i&-i)){
		bit[i]=max(bit[i],x);
	}
	return;
}

ll sum(int a){
	ll ret=0;
	for(int i=a;i>0;i-=(i&-i)){
		ret=max(ret,bit[i]);
	}
	return ret;
}

int main(){
	int x;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		add(x-1,sum(x-1)+x);
	}
	printf("%lld\n",(ll(n)*(n+1))/2-sum(n));
}


Measured memory_bytes: 4012
from math import sqrt, ceil

def min_mult(m):
  for i in xrange(int(ceil(sqrt(m))), 0, -1):
    if m % i == 0:
      return i, int(m/i)

def main():
  n = int(raw_input())
  a, b = min_mult(n)
  print(a-1 + b-1)

main()

Measured memory_bytes: 2568
#include<stdio.h>
#include<string.h>
int main(){
  char s[1002];
  char *w[1000]={0};
  int c[1000]={0};
  int i,r=0,mi,ml,max,maxl,l;
  fgets(s,1001,stdin);
  s[strlen(s)-1]=0;
  w[r++]=strtok(s," ");
  maxl=strlen(w[ml=0]);
  c[mi=0]=max=1;
  while(w[r++]=strtok(NULL," ")){
    c[r]=1;
    for(i=0;i<r-1;i++){
      if(strcmp(w[r-1],w[i])==0){
	c[i]++;
	if(max<c[i]){
	  max=c[i];
	  mi=i;
	}
	r--;
	break;
       }
    }
    l=strlen(w[i]);
    if(maxl<l){
      maxl=l;
      ml=i;
      }//*/
  }//for(i=0;i<r;i++)printf("%d ",c[i]); 
  printf("%s %s\n",w[mi],w[ml]);
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	int ma=0;
	int  mi=10000000000;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		ma=max(ma,a[i]);
		mi=min(mi,a[i]);
	}
	cout<<ma-mi<<endl;
}


Measured memory_bytes: 256
d=dict()
wa=ans=0
N,M=map(int,input().split())
for i in range(M):
  p,s=input().split()
  if p not in d:
    d[p]=0
  if d[p]>=0 and s=="AC":
    ans+=1
    wa+=d[p]
    d[p]=-float("inf")
  else:
    d[p]+=1
print(ans,wa)

Measured memory_bytes: 19276
# coding: utf-8
timestamp = 1

stack = []
indata = []
visit = []      #?¨?????¨????
visitTime = []  #?¨???????????¨??????¨
lastTimeStack = []      #?¨?????????????????¨??????¨


def inputdata():
    global      visit
    global      indata
    global      visitTime

    n = int(input().rstrip())

    for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v)

def procV(n):
    global lastTimeStack
    global timestamp
    global visit
    global stack

    if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1

"""
main
"""
inputdata()
stack.append(0)             #?????????????´????push??????

while True:
    if len(stack) == 0:
        isNotVisit = True
        n = 0
        for i in visit:
            if i:
                isNotVisit = False
                stack.append(n)
                break
            n += 1
        if isNotVisit:
            break

    n = stack.pop()         #??????????????????pop??????
    procV(n)                #pop????????????????????????????????????

    #???????????¢???
    for i in reversed(indata[n]):
        if visit[i]:
            hasNotChildAdd = False
            stack.append(i)

i = 1
for val in visitTime:
    li = [i, val[0], val[1]]
    print(' '.join(map(str, li)))
    i += 1

Measured memory_bytes: 7840
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

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

    int wl = 0, wr = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '.') {
            wr++;
        }
    }

    int res = wr;
    for (int i = 0; i < n; i++) {
        if (s[i] == '.') {
            wl++;
            wr--;
        }

        res = min(res, (i - wl + 1) + wr);
    }

    cout << res << endl;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
   int a, b;
  cin >> a >> b;
  int sum = 0;
  for (int i = 0; i < 2; i++) {
      if(a >= b) {
          sum += a;
          a--;
      } else {
          sum += b;
          b--;
      }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		int a = getInt(sc);
		int b = getInt(sc);

		int train = n * a;
		int taxi = b;

		System.out.println(Math.min(taxi, train));
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

using namespace std;

#define ll long long int

int main(){
	ll n;
	cin>>n;
	vector<string>v;
	for(ll i=0;i<n;i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		v.push_back(s);
	}
	sort(v.begin(),v.end());
	ll ans=0;
	ll cnt=1;
	for(ll i=1;i<v.size();i++){
	//	cout<<v[i]<<' '<<v[i-1]<<'\n';
		if(v[i]==v[i-1]){
			cnt++;
		}
		else{
			//cout<<ans<<' '<<i<<' '<<cnt<<" gggg \n";
			ans+=((cnt*(cnt-1))/2);
			
			cnt=1;
		}
	}
	ans+=((cnt*(cnt-1))/2);
	cout<<ans;
}

Measured memory_bytes: 5876
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#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 << '\n'; }
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__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int a , b , x ;
    cin >> a >> b >> x ;
    int ans = 0 ;
    if ( a == 0 ){
        ans = b / x + 1 ;
    }
    else ans = b / x - (a - 1) / x ; 
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int cnt =  0;
  for (int i=0; i < 3; i++) {
    if (s[i] == 'R')cnt++;
  }
  switch (cnt) {
    case 0: cout << "0" << endl;break;
    case 1: cout << "1" << endl; break;
    case 2:
    if (s[1]=='S') {cout << "1" << endl;}
    else {cout << "2" << endl;}
    break;
    case 3: cout << "3" << endl; break;
  }
  return 0;
}


Measured memory_bytes: 3624
#人のプログラムの全コピ　TKR18さん

#入力
a,b=map(int,input().split())
c=[0]+[list(map(int,input().split()))for i in range(a)]

#print(c)

def f(t,s): #t:t*100点までリストが存在する s: 目標値
    if t==0: #が0の時、とりあえず大きな数を返す
        return 10**9
    l=min(s//(t*100),c[t][0]) #s//(t*100): 目標を最高基本点で割った時の商、c[t][0]:最高基本点の使える数　これらの小さい方を返す
    k=100*t*l #最高基本点を使って得点できる最高点
    if l==c[t][0]: #最高基本点を使った数が、使える数と同じならボーナス点を加える。
        k+=c[t][1] 
    if k<s: #最高基本点を全て使って得点できる点が、目標点以下なら...
        l+=f(t-1,s-k) #最高気本点を除いたもので、残りの点数を計算する。
    return min(l,f(t-1,s)) #最高気本点を使うもの(l)と最高基本点を使わないもの(f(t-1,s)のうち最小のものを見つける
print(f(a,b))



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, M;
  cin >> N >> M;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  map<int, int> m;
  REP(i, N) m[A[i]]++;

  vector<int> cnt(M);
  vector<vector<int>> num(M);
  for(auto p : m){
    cnt[p.first%M] += p.second;
    num[p.first%M].emplace_back(p.second);
  }

  int ans = cnt[0]/2;
  FOR(i, 1, M){
    int j = M-i;
    if(j < i) break;
    if(i == j) ans += cnt[i]/2;
    else{
      int MIN = min(cnt[i], cnt[j]);
      ans += MIN;
      cnt[i] -= MIN; cnt[j] -= MIN;

      REP(k, num[i].size()){
        while(num[i][k] >= 2 && cnt[i] >= 2){
          ans++; num[i][k] -= 2; cnt[i] -= 2;
        }
      }
      REP(k, num[j].size()){
        while(num[j][k] >= 2 && cnt[j] >= 2){
          ans++; num[j][k] -= 2; cnt[j] -= 2;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 13568
N, M, X = gets.split(" ").map(&:to_i)
book = []
N.times do |i|
    book[i] = gets.split(" ").map(&:to_i)
end

min = 10**9

(2**N).times do |i|
    tmp = Array.new(M, 0)
    sum = 0
    i = i.to_s(2)
    while i.size < N do 
        i = "0" + i
    end
    i = i.chars
    i.each_with_index do |j, id|
        if j == "1"
            M.times do |k|
                tmp[k] += book[id][k + 1]
            end
            sum += book[id][0]
        end
    end
    if tmp.count{|x| x < X} == 0
        min = sum if min > sum
    end
end

if min == 10**9
    puts -1
else
    puts min
end



Measured memory_bytes: 14396
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {
    int n, k, r, s, p;
    scanf("%d %d %d %d %d\n", &n, &k, &r, &s, &p);
    char t[n+1];
    scanf("%s", t);
    int ans[n];
    for (int i = 0; i < n; i++) {
        if (t[i] == 'r') ans[i] = p;
        else if (t[i] == 's') ans[i] = r;
        else ans[i] = s;
    }
    for (int i = 0; i < n-k; i++) {
        if (t[i] == t[i+k]) {
            t[i+k] = '0';
            ans[i+k] = 0;
        }
    }
    int score = 0;
    for (int i = 0; i < n; i++) {
        score += ans[i];
    }
    printf("%d\n", score);
    return 0;
}


Measured memory_bytes: 640
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << "[" << pa.first << ", " << pa.second << "]";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  os << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "}";
  return os;
}

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

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

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

  ll a,b;
  std::cin>>a>>b;

  ll g=gcd(a,b);

  ll cnt=1,temp=g;

  for(ll i=2;i*i<=g;i++){
    if(temp==1)break;
    if(temp%i==0){
      cnt++;
      while(temp%i==0)temp/=i;
    }
  }

  if(temp!=1)cnt++;

  std::cout<<cnt;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
    public static Scanner sc;
    public static int[][] ary;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) break;
            ary = new int[n+1][n+1];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    ary[i][j] = sc.nextInt();
                }
            }
            
            for (int i = 0; i < n; i++) {
                int sum = 0;
                for (int j = 0; j < n; j++) {
                    sum += ary[i][j];
                }
                ary[i][n] = sum;
            }
            for (int i = 0; i < n; i++) {
                int sum = 0;
                for (int j = 0; j < n; j++) {
                    sum += ary[j][i];
                }
                ary[n][i] = sum;
            }
            int sum = 0;
            for (int i = 0; i < n; i++) {
                sum += ary[i][n];
            }
            ary[n][n] = sum;
            
            for (int i = 0; i < n+1; i++) {
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < n+1; j++) {
                    int num = ary[i][j];
                    for (int k = 0; k < (5 - Integer.toString(num).length()); k++) {
                        sb.append(" ");
                    }
                    sb.append(num);
                }
                System.out.println(sb.toString());
            }
        }
    }
}

Measured memory_bytes: 30108
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <cctype>

#if (__cplusplus >= 201703L)
#include <filesystem>
namespace fs = std::filesystem;
#endif

// boost
//#define USE_BOOST_IN_CODE
#ifdef USE_BOOST_IN_CODE
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/strided.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/format.hpp>
#endif

template <class T>
using vec = std::vector<T>;

void solve()
    {
        using namespace std;

        int n, k;
        cin >> n >> k;

        vec<int> v(n);

        for (auto& x : v)
            cin >> x;

        cout << accumulate(v.cbegin(), v.cend(), 0, 
            [k](int init, int x) 
            {
                return init + min(x, k - x) * 2;
            })
            << endl;

    }

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

string A,B,C;

int main(){
    cin>>A>>B>>C;
    if(A[A.length()-1]==B[0]&&B[B.length()-1]==C[0]){
        out("YES");
    }
    else{
        out("NO");
    }
}



Measured memory_bytes: 256
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ca = 0
cb = 0
s = 0
for i in range(N):
  if s+A[i] <= K:
    ca += 1
    s += A[i]
  else:
    break
#print(ca)
CA = ca
for i in range(M):
  if s+B[i] <= K:
    cb += 1
    s += B[i]
  else:
    break
ans = ca+cb
#print(ans)
for i in reversed(range(CA)):
  ca -= 1
  s -= A[i]
  for i in range(cb,M):
    if s+B[i] <= K:
      cb += 1
      s += B[i]
    else:
      break
  ans = max(ans,ca+cb)
print(ans)

Measured memory_bytes: 40760
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
        final int MOD = 1000000007;

        int n = sc.nextInt();
        int last = sc.nextInt() - 1;
        for(int i=0;i<n-1;i++) {
            int next = sc.nextInt();
            if(next - 1 >= last) {
                last = next - 1;
                continue;
            }
            if(next < last) {
                pw.println("No");
                pw.close();
                return;
            }
            last = next;
        }

        pw.println("Yes");
        pw.close();
    }
}


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

int main()
{
  int64_t A, B, K, z = 0;
  cin >> A >> B >> K;
  if (A - K >= 0)
    cout << A - K << ' ' << B << endl;
  else
    cout << 0 << ' ' << max(z, B - (K - A)) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 22:03:19 2020

@author: liang
"""

N, X, M = map(int,input().split())
mod_set = {X}
mod_lis = [X]
A = [0]*(10**6+1)
A[0] = X
flag = False
#for i in range(1,N):
"""
【for文のループ用の変数を、
　●for文外で使ったり
 ●for文内で書き換えたり
 してはいけない】
 (理由)
●for文外で使うとき、for文に入らない入力値の場合
　　【未定義】
　となり、エラーが出る。　
 ⇒　【for文外で定義済み】の他の変数に保存する
●for文内で書き換えると、ループが壊れてしまう
 ⇒　一旦別の変数に保存し、その変数を書き換える

【整数の切り捨て演算は計算順序に注意】
*ans += T_sum * (N-j)//T
　⇒T_sum * (N-j)　を Tで割っているのでダメ
<対策 1: 切り捨て演算は括弧で囲む>
 ⇒ans += T_sum * ( (N-j)//T )
<対策 2: 切り捨て演算は予め計算しておく>
 ●divmod(a,b) => return (a//b,a%b)

"""
l = 1
for i in range(1,min(10**6,N)):
    l = i
    tmp = A[i-1]**2%M
    if tmp in mod_set:
        flag = True
        break
    A[i] = tmp
    mod_set.add(tmp)
    mod_lis.append(tmp)

if flag:
    j = mod_lis.index(tmp)
else:
    j = l
T = l - j
ans = 0
if T != 0:  
    #print("A")
    ans += sum(mod_lis[:j])
    T_sum = sum(mod_lis[j:])
    q, r = divmod(N-j,T)
    ans += T_sum * q
    #print((N-j)//T, T_sum)
    T_lis = mod_lis[j:]   
    ans += sum(T_lis[:r])
else:
    #print("B")
    ans = sum(mod_lis)
   # print(mod_lis)
#print(T_lis)
#print((N-j)%T)
#print(T_lis[:10])
print(ans)
#print(T_sum)
#print(sum(T_lis))

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int x;
  cin>>x;
  int s = 0, t = x;
  while(t){
    s += t%10; t /= 10;
  }
  puts(x%s==0 ? "Yes" : "No");
  return 0;
}


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

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)>d){
    if(abs(a-b)>d || abs(b-c)>d){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
    else {
      cout << "Yes" << endl;
    }
}

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

int main()
{
  int N;
  float vsum;
  
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  vsum = (v.at(0) + v.at(1)) / 2.0;
  for (int i = 2; i < N; i++) {
    vsum = (vsum + v.at(i)) / 2.0;
  }
  cout << vsum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    cin >> L;
    sort(ALL(L));
    lint ret = 0;
    REP(i, N) REP(j, i) REP(k, j) if (L[j] + L[k] > L[i]) ret++;
    cout << ret << endl;
}


Measured memory_bytes: 256
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
a=[]
for i in range(n):
    for j in range(n):
        if i!=j:
            a.append([l[i][0]-l[j][0],l[i][1]-l[j][1]])
#print(a)
m=len(a)
ans=0
for k in range(m):
    c=0
    p=a[k][0]
    q=a[k][1]
    for i in range(n):
        for j in range(n):
            if i!=j and [l[i][0]-l[j][0],l[i][1]-l[j][1]]==[p,q]:
                c+=1
    ans=max(ans,c)
if n==1:
    print(1)
else:
    print(n-ans)



Measured memory_bytes: 43116
s = input()
a_cnt = s.count("a")
b_cnt = s.count("b")
c_cnt = s.count("c")
cnt = len(s)
if max(a_cnt, b_cnt, c_cnt) - min(a_cnt, b_cnt, c_cnt) <= 1:
    print("YES")
else:
    print("NO")

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    
    map<int, int> mp;
    for(int i = 0; i < N; i++){
        if (mp.count(A.at(i))){
            mp.at(A.at(i))++;
        }
        else{
            mp[A.at(i)] = 1;
        }
    }
    
    int count = 0;
    for(int i = 0; i < N; i++){
        if (mp.at(A.at(i))%2 == 1){
            count ++;
            mp.at(A.at(i)) = 0;
        }
    }
    
    cout << count << endl;
    
}


Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for (auto& e : a) std::cin >> e;

    int M;
    std::cin >> M;
    std::vector<int> b(M);
    for (auto& e : b) std::cin >> e;

    std::vector<int> ans;
    std::set_symmetric_difference(a.begin(), a.end(),
                                  b.begin(), b.end(),
                                  std::back_inserter(ans));

    for (auto& e : ans) std::cout << e << std::endl;
    return 0;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

double dp[3000][3000];

int main(){
  int n; cin>>n;
  vector<double> p(n);
  rep(i,n) cin>>p[i];
  
  dp[0][0]=1;
  rep(i,n){
    for(int j=0; j<=i; j++){
      dp[i+1][j+1]+=dp[i][j]*p[i]; // i番目が表
      dp[i+1][j]+=dp[i][j]*(1-p[i]); // 裏
    }
  }
  double ans=0;
  for(int i=n/2+1; i<=n; i++){
    ans+=dp[n][i];
  }
  coutd(ans);
}

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

using namespace std;

const int N = 200005;

int n;
int a[N];

int main() {

	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	int cur = 1;
	for (int i = 1; i <= n; i ++) {
		if (a[i] == cur) {
			cur ++;
		}
	}
	cout << ((cur != 1) ? (n - cur + 1) : -1) << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;

ll mod = 1e9+7;

ll add(ll a, ll b) { return (a % mod + b % mod) % mod; }
ll mul(ll a, ll b) { return (a % mod * b % mod) % mod; }
ll debug(vector<int> a) { for(int i: a) cout << i << " "; return puts("\n"), 0;}

ll power(ll base, ll exp) {
    ll res = 1;
    while(exp) {
        if(exp&1) res = mul(res, base);
        base = mul(base, base);
        exp >>= 1;
    }
    return res;
}
ll inv(ll p) {
    return power(p, mod-2);
}
ll fact[2000003] = {0};
int main() {
    fastio
    fact[0] = 1;
    for(int i=1; i<=2000002; i++) fact[i] = mul(fact[i-1], i);
    ll x, y;
    cin >> x >> y;
    if((x+y)%3 != 0) return puts("0"), 0;
    ll n = (2*y-x)/3, m = (2*x-y)/3;
    if(n < 0 || m < 0) {
        cout << "0";
        return 0;
    }
    ll num = fact[n+m];
    ll den = mul(fact[n], fact[m]);
    ll ans = mul(num, inv(den));
    cout << ans << "\n";

}

Measured memory_bytes: 15872
s = input().rstrip()
q = int(input().rstrip())
f = True

a = []
z = []
for _ in range(q):
    c = input().rstrip()
    if c == "1":
        f = not f
    else:
        _, cc, ccc = c.split()
        if (cc == "1") == f:
            a.append(ccc)
        else:
            z.append(ccc)

aa = "".join(a[::-1])
zz = "".join(z)
s = aa + s + zz

if f:
    print(s)
else:
    print(s[::-1])


Measured memory_bytes: 6272
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

string s;

int main() {
    string ref = "CODEFESTIVAL2016"; cin >> s;

    int res = 0;

    FORN(i, ref.size()) {
        res += (ref[i] != s[i]);
    }

    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N, K = map(int, input().split())
a = list(map(int, input().split()))
acc = [0] + list(accumulate(a))
ss = []
for r in range(N):
    for l in range(r+1):
        ss.append(acc[r+1] - acc[l])
ans = 0
idx = list(range(len(ss)))
for i in range(40)[::-1]:
    nidx = []
    for j in idx:
        if ss[j] >> i & 1 == 1:
            nidx.append(j)
    if len(nidx) >= K:
        ans += 1 << i
        idx = nidx
print(ans)




Measured memory_bytes: 78832
#include<stdio.h>
int main(){
	int n,m;   // n even m odd
	int sum1=0;
	int sum2=0; 
	scanf("%d %d",&n,&m);
	
	if(n>1){
		for(int i=1;i<n;i++){
			sum1+=i;
		}
	}
	if(m>1){
		for(int i=1;i<m;i++){
			sum2+=i;
		}
	}
	printf("%d", sum1+sum2);
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> l(N);
  vector<int> r(N);
  int sum = 0, ans = 0;;
  for(int i = 0; i < N; i++){
    cin >> l[i] >> r[i];
    ans = r[i] - l[i] + 1;
    sum += ans;
  }
  cout << sum << 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 For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(c)  (c).begin(),(c).end()
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n;

int main(){
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }
    REP(i,n){
        a[i]*=n;
        a[i]=abs(sum-a[i]);
    }
    int m=INT_MAX;
    int res = 0;
    REP(i,n){
        if(chmin(m,a[i])){
            res = i;
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = []
C = []

for i in range(N):
    a, b = map(int, input().split())
    S.append((a, b))

for i in range(M):
    c, d = map(int, input().split())
    C.append((c, d))

for si in S:
    ans = -1
    min_ = 10 ** 10
    for i, ci in enumerate(C):
        ds = abs(ci[0] - si[0]) + abs(ci[1] - si[1])
        if ds < min_:
            min_ = ds
            ans = i
    print(ans + 1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	cin >> str;
	if(str.size()==2)
	{
		cout << str << endl;
	}
	else 
	{
		reverse(str.begin(), str.end()); 
		cout << str << endl;
	}
}

Measured memory_bytes: 256
while 1:
	n=input()
	if n==0:break
	b=map(int,raw_input().split())
	i=2
	c=int((b[n-2]*b[n-1]/b[-1])**0.5)
	print c
	print " ".join(map(str,sorted([b[i]/c for i in range(n)])))
	
	

Measured memory_bytes: 8632
use std::io::*;
use std::str::*;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let a: i32 = buf.trim_right().parse().unwrap();

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let b: i32 = buf.trim_right().parse().unwrap();

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let c: i32 = buf.trim_right().parse().unwrap();

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let x: i32 = buf.trim_right().parse().unwrap();
   
    let mut count = 0;

    for i in 0..a + 1 {
        for j in 0..b + 1 {
            for k in 0..c + 1 {
                let sum = 500 * i + 100 * j + 50 * k;
                if sum == x {
                    count += 1;
                }
            }
        }
    }

    let out = stdout();
    let mut out = out.lock();
    writeln!(out, "{}\n", count);

}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void)
{
	int n,a[101],i,j,tmp;
	int b=0,c=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			if(a[i]<a[j]){
				tmp=a[i];
				a[i]=a[j];
				a[j]=tmp;
			}
		}
	}
	for(i=0; i<n; i++){
		if(i%2==0){
			b=b+a[i];
		}else if(i%2==1){
			c=c+a[i];
		}
	}
	printf("%d\n",b-c);
	return 0;
}

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

const int maxh = 20;
const int maxw = 1e3 + 10;
const int inf = 1e9 + 7;

int ans;
int h, w, k;
int block[maxh];
int val[maxh][maxw];

void in();
void solve();
void out();

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

void in(){
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            val[i][j] = c - '0';
        }
    }
}

void solve(){
    ans = inf;
    for(int i = 0; i < (1 << (h - 1)); i++){
        int lastcut = -1;
        int thisans = __builtin_popcount(i);
        for(int i = 0; i < h; i++)
            block[i] = 0;
        for(int j = 0; j < w; j++){
            int nowb = 0;
            for(int z = 0; z < h; z++){
                block[nowb] += val[z][j];
                if((1 << z) & i)
                    nowb++;
            }
            for(int z = 0; z < h; z++){
                if(block[z] > k && lastcut + 1 == j){
                    thisans = inf;
                    break;
                }
                else if(block[z] > k){
                    lastcut = j - 1;
                    thisans++;
                    for(int i = 0; i < h; i++)
                        block[i] = 0;
                    j--;
                }
            }
        }
        ans = min(ans, thisans);
    }
}

void out(){
    cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#include<limits.h>

#define NUM 51

int main(){
	int n, m, a, b;
	int p[NUM];
	scanf("%d%d\n", &n, &m);
	for(int i=1; i<=n; i++){
		p[i] = 0;
	}
	for(int i=0; i<m; i++){
		scanf("%d%d\n", &a, &b);
		p[a]++;
		p[b]++;
	}
	for(int i=1; i<=n; i++){
		printf("%d\n", p[i]);
	}
	return 0;
}



Measured memory_bytes: 128
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n=int(input())
    *a,=map(int,input().split())
    print(min(abs(sum(a[:i])-sum(a[i:]))for i in range(n)))
        
if __name__ == '__main__':
    main()

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

int A[25], B[25], C[25];
int ans;
int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) cin >> A[i];
	for (int i = 1; i <= n; ++i) cin >> B[i];
	for (int i = 1; i <= n-1; ++i) cin >> C[i];
	int eat = 0;
	for (int i = 1; i <= n; ++i)
	{
		ans += B[A[i]];
		if (A[i] == eat+1) ans += C[eat];
		eat = A[i];
	}
	cout << ans;
}
	

Measured memory_bytes: 256
def sub_cnt(c, b):
    cnt = 0
    for i in b:
        while c >= i:
            c -= i
            cnt += 1
    return cnt

n = int(input())

b6 = [6**i for i in range(6, -1, -1)]
b9 = [9**i for i in range(5, -1, -1)]

ans = 10**9
n9 = n // 9
for c9 in range(n9+1):
    cnt = 0
    cn = n - c9*9
    c6 = cn // 6
    c1 = cn % 6
    
    cnt += sub_cnt(c9, b9)
    cnt += sub_cnt(c6, b6)
    cnt += c1
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 9172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		printAFrame();

	}
	
	public static void printAFrame() {
		
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if (H == 0 && W == 0) {
				
				break;
			}

			for (int i = 0; i < H; i++) {
				
				for (int j = 0; j < W; j++) {
					
					if (1 <= i && i < H - 1 && 1 <= j && j < W - 1) {
						
						 System.out.print(".");
					} else {
						
						System.out.print("#");
					}
				}
				System.out.println("");
			}
			
			System.out.println("");
		}
	}
}


Measured memory_bytes: 34068
import math

n, k = map(int, input().split())

ans_list = []

def C(x, y):
    return math.factorial(x) // math.factorial(x - y) // math.factorial(y)

def calc(n, k, t):
    return C(n - k + 1, t) * C(k - 1, t - 1) % (10 ** 9 + 7)

for i in range(1, k + 1):
    
    if n - k <= 0:
        if len(ans_list) == 0:
            ans_list.append(1)
        else:
            ans_list.append(0)
    else:
        if i > (n - k + 1):
            if len(ans_list) == 0:
                ans_list.append(1)
            else:
                ans_list.append(0)
        else:
            ans_list.append(calc(n, k, i))

for i in ans_list:
    print(i)
        


Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

pair<int, int> pp[99999];
int v[99999];

int main(void)
{
	int h, w, d, q, i, j, a, L, R;

	scanf("%d %d %d" ,&h, &w, &d);
	for (i = 1; i <= h; i++)
		for (j = 1; j <= w; j++)
		{
			scanf("%d" ,&a);
			pp[a] = make_pair(i, j);
		}

	for (i = d + 1; i <= h * w; i++)
		v[i] = v[i - d] + abs(pp[i - d].first - pp[i].first) + abs(pp[i - d].second - pp[i].second);

	scanf("%d" ,&q);
	while (q--)
	{
		scanf("%d %d" ,&L, &R);

		printf("%d\n" ,v[R] - v[L]);
	}
	return 0;
}

Measured memory_bytes: 2048