akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;


long long N, K;
long long R, S, P;
string T;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;
	cin >> R >> S >> P;
	cin >> T;
	int oops[100000+2] = {0};

	long long ans = 0;
	for(int i=0; i<K; i++){
		long long v = 0;
		int pos1, pos2;
		pos1 = i;
		if(T[pos1] == 'r') v = P;
		if(T[pos1] == 's') v = R;
		if(T[pos1] == 'p') v = S;
		
		for(int j=1; ; j++){
			int pos2 = i + (j * K) ;
			if(pos2 >= N) break;
			if(T[pos2] == T[pos1]){
				if( j== 1 || oops[pos1] == 0){
					oops[pos2] = 1;
				}
				else{
					if(T[pos2] == 'r') v += P;
					if(T[pos2] == 's') v += R;
					if(T[pos2] == 'p') v += S;
				}
			}
			else{
				if(T[pos2] == 'r') v += P;
				if(T[pos2] == 's') v += R;
				if(T[pos2] == 'p') v += S;
			}
			pos1 = pos2;
		}
		ans += v;
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define loop(i,a,b) for(ll i=a; i<b; i++)
#define rloop(i,a,b) for(ll i=a; i>b; i--)
#define all(var) var.begin(), var.end()
#define eloop(var) for(auto elem : var)
#define debug(x) cerr<<#x<<" ----> "<<x<<endl;
#define TT ll tt; cin>>tt; while(tt--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define MOD 1000000007
#define MAX 100005
typedef long long ll;
typedef long double ld;

map<ll, ll> m;

ll find(ll h) {
    ll ans = 1;
    if(m.find(h) != m.end())
        return m[h];
    ans += find(h/2)*2;
    m[h] = ans;
    return m[h];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //TT
    {
        ll h;
        cin>>h;
        m[1] = 1;
        ll ans = find(h);
        cout<<ans<<'\n';
    }
    return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        char octal[16] = {};
        sprintf(octal, "%o", n);
        for (int i = 0; octal[i] != '\0'; i++) {
            if (octal[i] == '4') {
                octal[i]++;
            } else if ('5' <= octal[i] && octal[i] <= '7') {
                octal[i] += 2;
            }
        }
        cout << octal << endl;
    }
}

Measured memory_bytes: 892
anss = ['Positive','Negative','Zero']
a,b = map(int,input().split())
if a*b <= 0: ans = 2
elif a > 0 and b > 0: ans = 0
elif a == b: ans = 0
else:
    if (b-a) % 2 == 0: ans = 1
    else: ans = 0
print(anss[ans])

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#define LL long long 
using namespace std;
int a,b,c;LL k;
const LL mb=1e18;
struct mat
{
	LL sq[5][5];
	void cl(){memset(sq,0,sizeof(sq));}
}mul,ans;
mat cf(mat a,mat b)
{
	mat c;c.cl();
	for (int i=1;i<=3;i++)
	  for (int j=1;j<=3;j++)
	    for (int k=1;k<=3;k++)
	      c.sq[i][j]=(a.sq[i][k]*b.sq[k][j]+c.sq[i][j]);
	return c;
}
mat ksm(mat a,LL k)
{
	mat ans=a;k--;if (k<=0) return ans;
	for (;k;k>>=1,a=cf(a,a))
  	  if (k&1) ans=cf(ans,a);
    return ans;
}
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	scanf("%lld",&k);
	if (k==0) {printf("%d",a-b);return 0;}
	mul.sq[1][1]=0; mul.sq[2][1]=1; mul.sq[3][1]=1; 
	mul.sq[1][2]=1; mul.sq[2][2]=0; mul.sq[3][2]=1; 
	mul.sq[1][3]=1; mul.sq[2][3]=1; mul.sq[3][3]=0; 
	mul=ksm(mul,k);
	ans.sq[1][1]=a*mul.sq[1][1]+b*mul.sq[2][1]+c*mul.sq[3][1];
	ans.sq[1][2]=a*mul.sq[1][2]+b*mul.sq[2][2]+c*mul.sq[3][2];
	ans.sq[1][3]=a*mul.sq[1][3]+b*mul.sq[2][3]+c*mul.sq[3][3];
    if (ans.sq[1][1]-ans.sq[1][2]>mb) printf("Unfair");else printf("%lld",ans.sq[1][1]-ans.sq[1][2]);
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  if(b - a == c - b){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
//  IT'S NEVER TOO LATE...

#include <bits/stdc++.h>
#include <complex>
#define ll long long

#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define fori(i, l, r) fore(i, l, (r) + 1)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ms(m) memset(m,0,sizeof(m))

//#define C complex<int>
#define X real()
#define Y imag()

using namespace std; 

const double PI = atan(1)*4;
#define inf 1e9
const int mod=1e9+7;



int main()
{

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

    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
    int tt=1;
    //cin>>tt;

    while(tt--)
    {
        //matrix mat(n),m2(n);

    	int a,b,c,d;
    	cin>>a>>b>>c>>d;

    	cout<<max((ll)a*c,max((ll)a*d,max((ll)b*c,(ll)b*d)));
    }
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

    return 0;
    	
}
                //              NOW IT'S TIME TO WAKE UP... 








Measured memory_bytes: 3812
# 人を頂点と見なしたグラフを作る。有向で、逆向きの場合は正負を反転させて辺を張る
# 頂点からの距離を記録し、一致しない箇所があればNG。
# 全ての辺を通るまで続ける。
# 辺の情報を[{0から行ける頂点},{1から行ける頂点},...]で管理する
# 親には進まないようにしてDFSする

N,M = map(int,input().split())
E = [[] for i in range(N)]
for i in range(M):
  L,R,D = map(int,input().split())
  E[L-1].append([R-1,D])
  E[R-1].append([L-1,-D])
from collections import deque
# 頂点、親、距離
INF = 10 ** 10
dist = [INF] * N
for i in range(N):
  if dist[i] != INF:
    continue
  dist[i] = 0
  q = deque()
  # 頂点、親
  q.append([i,-1])
  while q:
    v,parent = q.pop()
    for child in E[v]:
      if child[0] == parent:
        continue
      if dist[child[0]] == INF:
        dist[child[0]] = dist[v] + child[1]
        q.append([child[0],v])
      else:
        if dist[child[0]] != dist[v] + child[1]:
          print("No")
          exit(0)
else:
  print("Yes")


Measured memory_bytes: 85596
#include <iostream>

using namespace std;

int main(){
  int a,b,ans=0;
  cin >> a >> b;

  for(int i=0; i < 2; i++) {
    if (a > b){
      ans += a;
      a--;
    }else{
      ans += b;
      b--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

MOD = 10**9 + 7

n, k, *ab = map(int, sys.stdin.read().split())
ab = zip(*[iter(ab)] * 2)
g = [[] for _ in range(n+1)]
for a, b in ab:
    g[a].append(b)
    g[b].append(a)

def main():
    stack = [1]
    coloring = [None] * (n + 1); coloring[1] = k
    par = [None] * (n + 1)
    while stack:
        u = stack.pop()
        r = k - 1
        if par[u]:
            r -= 1
        for v in g[u]:
            if v != par[u]:
                par[v] = u
                if r < 0:
                    return 0
                coloring[v] = r
                r -= 1
                stack.append(v)
    
    res = 1
    for i in range(1, n+1):
        res *= coloring[i]
        res %= MOD
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 27812
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int N, M;
    std::cin >> N >> M;
    std::vector<bool> succeedTable(N);
    
    int totalSucceedCount = 0;
    std::vector<int> penaltyCountTable(N);

    for (int i=0; i<M; ++i)
    {
      int pi;
      std::string result;
      std::cin >> pi >> result;
    
      pi -= 1;
      if (!succeedTable[pi])
      {
          if (result == "AC")
          {
            succeedTable[pi] = true;
            totalSucceedCount++;
          }
          else
          {
            penaltyCountTable[pi]++;
          }
      }
    }

    long long totalPenaltyCount = 0;
    for (int i=0; i < penaltyCountTable.size(); ++i)
    {
      if (succeedTable[i])
        totalPenaltyCount += penaltyCountTable[i];
    }

    std::cout << totalSucceedCount << ' ' << totalPenaltyCount;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var dts = RSInt;
            WriteLineYes_or_No(dts[0] <= dts[1] * dts[2]);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w, d, a[300][300], q;
pair<int, int> pos[300 * 300];
vector<int> ord;
bool vis[300 * 300];
int at[300 * 300];

LL sum[300 * 300 + 1];

int main() {
	cin >> h >> w >> d;
	inc(i, h) {
	inc(j, w) {
		cin >> a[i][j];
		a[i][j]--;
		pos[a[i][j]] = MP(i, j);
	}
	}
	
	inc(i, d) {
		inc(j, w * h) {
			int k = (i + j * d) % (h * w);
			if(vis[k]) { break; }
			vis[k] = true;
			ord.PB(k);
		}
	}
	inc(i, h * w) { at[ord[i]] = i; }
	
	incID(i, 1, h * w) {
		sum[i] = abs(pos[ord[i]].FI - pos[ord[i - 1]].FI) + abs(pos[ord[i]].SE - pos[ord[i - 1]].SE);
	}
	
	inc(i, h * w) { sum[i + 1] += sum[i]; }
	
	cin >> q;
	inc(qq, q) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		
		cout << sum[at[r]] - sum[at[l]] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 3832
package main

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
}

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	n, _ := strconv.Atoi(ReadString())
	return n
}

func readInt64() int64 {
	n, _ := strconv.ParseInt(ReadString(), 0, 64)
	return n
}

// 10 11 12 => [10, 11, 12]
func readIntSlice(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

func main() {
	x := readInt64()
	s := float64(100)
	var i int
	for i = 0; i < 5000; i++ {
		s = math.Floor(s * 1.01)
		if s >= float64(x) {
			break
		}
	}
	fmt.Println(i + 1)
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    string S;
    while(true){
        cin >> S;
        if(S[0] == '#') break;
        vector<int> dir; //0 -> north 1 -> west
        int idx = 0;
        int lenS = S.length();
        while(idx < lenS){
            if(S[idx] == 'n'){
                dir.push_back(0);
                idx += 5;
            }
            else{
                dir.push_back(1);
                idx += 4;
            }
        }
        int beki = (1 << (dir.size()-1));
        int ans;
        reverse(dir.begin(), dir.end());
        for(int i = 0; i < dir.size(); i++){
            if(i == 0){
                if(dir[i]) ans = 90*beki;
                else ans = 0;
            }
            else{
                if(dir[i]) ans += 90*beki/(1 << i);
                else ans -= 90*beki/(1 << i);
            }
        }
        while(ans % 2 == 0 && beki % 2 == 0){
            ans /= 2;
            beki /= 2;
        }
        if(beki > 1) cout << ans << "/" << beki << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
from fractions import gcd


def main():
    a, b, k = map(int, input().split())
    d = []
    g = gcd(a, b)
    i = 1
    while i * i <= g:
        if g % i == 0:
            d.append(i)
            if i * i != g:
                d.append(g // i)
        i += 1
    d.sort()
    print(d[-k])


if __name__ == '__main__':
    main()



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

constexpr int MAX = 500010;

struct Node{
  int key;
  Node* left;
  Node* right;
  Node* p;
};

Node gT[MAX];
Node* gRoot = nullptr;

Node* GetSuccessor( Node* x ){
  if( x->right != nullptr ){
    Node* z = x->right;
    while( z->left != nullptr ){
      z = z->left;
    }
    return z;
  }

  Node* y = x->p;
  while( y != nullptr && x == y->right ){
    x = y;
    y = x->p;
  }
  return y;
}

void Insert( int k ){
  Node* y = nullptr;
  Node* x = gRoot;
  Node* z = new Node;
  z->key = k; z->left = nullptr; z->right = nullptr;
  
  while( x != nullptr ){
    y = x;
    if( z->key < x->key ) x = x->left;
    else                  x = x->right;
  }
  z->p = y;

  if( y == nullptr ){
    gRoot = z;
  }else if( z->key < y->key ){
    y->left = z;
  }else{
    y->right = z;
  }
}

Node* Find( int k ){
  Node* x = gRoot;
  while( x != nullptr ){
    if( k == x->key ) return x;
    if( k < x->key ) x = x->left;
    else x = x->right;
  }
  return nullptr;
}

void Delete( int key ){
  Node* x = Find( key );
  if( x->left == nullptr && x->right == nullptr ){
    if( x->p->left == x ){
      x->p->left = nullptr;
      delete x;
      x = nullptr;
    }else{
      x->p->right = nullptr;
      delete x;
      x = nullptr;
    }
  }else if( x->left != nullptr && x->right != nullptr ){
    Node* s = GetSuccessor( x );
    int t = s->key;
    Delete( s->key );
    x->key = t;
  }else if( x->left != nullptr ){
    if( x->p->left == x ){
      x->p->left = x->left;
      x->left->p = x->p;
      delete x;
      x = nullptr;
    }else{
      x->p->right = x->left;
      x->left->p = x->p;
      delete x;
      x = nullptr;
    }
  }else{
    if( x->p->left == x ){
      x->p->left = x->right;
      x->right->p = x->p;
      delete x;
      x = nullptr;
    }else{
      x->p->right = x->right;
      x->right->p = x->p;
      delete x;
      x = nullptr;
    }
  }
}


void Inorder( Node* s ){
  if( s == nullptr ) return;

  Inorder( s->left );
  cout << " " << s->key;
  Inorder( s->right );
}

void Preorder( Node* s ){
  if( s == nullptr ) return;

  cout << " " << s->key;
  Preorder( s->left );
  Preorder( s->right );
}

int main(){
  for( int i = 0; i < MAX; i++ ){
    gT[i].left = gT[i].right = gT[i].p = nullptr;
  }
  
  int m; cin >> m;
  for( int i = 0; i < m; i++ ){
    char cmd[10]; cin >> cmd;
    if( cmd[0] == 'i' ){
      int key; cin >> key;
      Insert( key );
    }else if( cmd[0] == 'p' ){
      Inorder( gRoot ); cout << endl;
      Preorder( gRoot ); cout << endl;
    }else if( cmd[0] == 'f' ){
      int key; cin >> key;
      if( Find( key ) != nullptr ) cout << "yes" << endl;
      else cout << "no" << endl;
    }else if( cmd[0] == 'd' ){
      int key; cin >> key;
      Delete( key );
    }
  }
}



Measured memory_bytes: 37488
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define mp make_pair
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int DMAX=1000000+5;
const int MOD=1000000000+7;
template<class T> inline void read(T &x){
	x=0;
	T f=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch<='9' && ch>='0'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	x*=f;
}
int a,b,c;
int main(){
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>
#include <cstring>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, y;
    cin >> n >> y;
    rep(i, n+1) rep(j, n-i+1) {
        if (10000*i + 5000*j + 1000*(n-i-j) == y) {
            cout << i << " " << j << " " << n-i-j << endl;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 3580
S = input()
good = 1
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "R" or S[i] == "U" or S[i] == "D":
            # print(1)
            good = good
        else:
            good = 0
    else:
        if S[i] == "L" or S[i] == "U" or S[i] == "D":
            # print(2)
            good = good
        else:
            good = 0

if not good:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 38256
I=lambda:list(map(int,input().split()))
N,W=I()
g={}
for _ in[0]*N:
  a,b=I()
  g[a]=g.get(a,[])+[b]
*w,=g.keys()
v=[]
for i in range(len(w)):
  s=[0]+sorted(g[w[i]])[::-1]
  for i in range(1,len(s)):
    s[i]+=s[i-1]
  v.append(s)
for i in range(len(w),4):
  w.append(10**18+i)
  v.append([0,10**18])
ans=0
for i in range(len(v[0])):
  s0=w[0]*i
  for j in range(len(v[1])):
    s1=s0+w[1]*j
    if s1>W:break
    for k in range(len(v[2])):
      s2=s1+w[2]*k
      if s2>W:break
      l=min((W-s2)//w[3],len(v[3])-1)
      ans=max(ans,v[0][i]+v[1][j]+v[2][k]+v[3][l])
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

namespace AtCoderBeginnerContest142_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] aiStr = Console.ReadLine().Split(' ');

            List<student> students = new List<student>();
            for (int i = 0; i < N; i++)
            {
                student current = new student();
                current.ID = (i + 1).ToString();
                current.Ai = int.Parse(aiStr[i]);
                students.Add(current);
            }

            students.Sort((a, b) => a.Ai - b.Ai);
            string ans = "";
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(students[i].ID);
            }


            //Console.ReadKey();
        }

        public class student
        {
            public int Ai { get; set; }
            public string ID { get; set; }
        }
    }
}


Measured memory_bytes: 32668
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];for(int i=0;i<N;i++) {}
		//Ae2+Be2=Ce2
		//StringBuffer str = new StringBuffer(hoge1);
		//for(int i=0;i<N;i++) {}
		
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		int a[]=new int[N];
		int sum=0;
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			sum+=a[i];
		}
		sum/=N;
		//sum--;
		
		int ans=10000009;
		
		for(int c=0;c<2;c++) {
			int tmp=0;
			for(int i=0;i<N;i++) {
				tmp+=(sum-a[i])*(sum-a[i]);
			}
			ans=Math.min(ans, tmp);
			sum++;
		}
		
		p(ans);
	
	}
	
		
	
	
		
	
	public static long modPow(long g,long N) {
		long T=1;
		for(int i=0;i<N;i++) {
			T*=g;
			T%=mod;
		}
		return T;
	}
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
vector<int> g[505];
int n, m, q, s, t, h[505][505];
int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=m;i++){
		scanf("%d%d", &s, &t);
		g[s].push_back(t);
	}
	for(int i=1;i<=n;i++){
		sort(g[i].begin(), g[i].end());
		for(int v:g[i]){
			h[i][v]++;
		}
		for(int j=i-1;j<=n;j++){
			h[i][j]+=h[i][j-1];
		}
	}
	for(int i=1;i<=q;i++){
		scanf("%d%d", &s, &t);
		int ans=0;
		for(int j=s;j<=t;j++){
			ans+=h[j][t];
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b==c+d) cout << "Balanced";
  else if(a+b>c+d) cout << "Left";
  else cout << "Right";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int x,y;
ll fac[maxn];
void init(){
	fac[0] = 1;
	for(int i = 1;i < maxn;i++) fac[i] = (fac[i-1] * i) % mod;
}
ll C(int n,int m){
	if(n < m) return 0;
	if(m == 0 || m == n) return 1;
	ll ans = (fac[n] * poww(fac[m],mod-2,mod))% mod * poww(fac[n-m],mod-2,mod) % mod;
	return ans;
}
void solve(){
	if((x + y) % 3 != 0){
		cout << 0 << endl;
		return;
	}
	int a = 2 * (x + y) / 3 - x; //a step of (i+1,j+2)
	int b = x - (x + y) / 3; //b step of (i+2,j+1)
	if(a < 0 || b < 0) cout << 0 << endl;
	else cout << C(a+b,a) << endl;
	return;
}
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	init();
	cin >> x >> y;
	solve();	
	return 0; 
}
//do smt instead of nothing! never give up!

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int x, n;
  cin >> x >> n;
  if(n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  bool hasx = false;
  rep(i, n) {
    cin >> p[i];
    if(p[i] == x) hasx = true;
  }
  if(!hasx) {
    cout << x << endl;
    return 0;
  }

  int i = 1;
  while(true) {
    int l = x - i;
    int r = x + i;
    bool ok = true;
    rep(i, n) {
      if(p[i] == l) ok = false; 
    }
    if(ok) {
      cout << l << endl;
      return 0;
    }
    ok = true;
    rep(i, n) {
      if(p[i] == r) ok = false; 
    }
    if(ok) {
      cout << r << endl;
      return 0;
    }
    i++;
  }
  return 0;
}

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

int main()
{
	int N;
	string S, T, R;
	cin >> N;	
	cin >> S >> T;
	for (int i = 0; i < N; i++) {
		R += S[i];
		R += T[i];
	}
	cout << R << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdio>
using namespace std;

struct FenwickTree {
	typedef int T;
	vector<T> v;
	void init(int n) { v.assign(n, 0); }
	void add(int i, T x) {
		for(; i < (int)v.size(); i |= i + 1) v[i] += x;
	}
	T sum(int i) const {	//[0, i)
		T r = 0;
		for(-- i; i >= 0; i = (i & (i + 1)) - 1) r += v[i];
		return r;
	}
	T sum(int left, int right) const {	//[left, right)
		return sum(right) - sum(left);
	}
};

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> p(N);
		for(int i = 0; i < N; ++ i) {
			scanf("%d", &p[i]), -- p[i];
		}
		int BlockSize = 500;
		int NumBlocks = N / BlockSize + 1;
		vector<vector<long long> > memo(NumBlocks, vector<long long>(N));
		FenwickTree ft;
		for(int bi = 0; bi < NumBlocks; ++ bi) {
			vector<long long> &v = memo[bi];
			int i = bi * BlockSize;
			{
				ft.init(N);
				long long sum = 0;
				for(int j = i; j < N; ++ j) {
					sum += (j - i) - ft.sum(p[j]);
					v[j] = sum;
					ft.add(p[j], 1);
				}
			}
			{
				ft.init(N);
				long long sum = 0;
				for(int j = i - 1; j >= 0; -- j) {
					sum += ft.sum(p[j]);
					v[j] = sum;
					ft.add(p[j], 1);
				}
			}
		}
		vector<vector<pair<int, int> > > sortedBlocks(NumBlocks);
		vector<int> rankInBlock(N, -1);
		for(int bi = 0; bi < NumBlocks; ++ bi) {
			int L = bi * BlockSize, R = min((bi + 1) * BlockSize, N);
			vector<pair<int, int> > &v = sortedBlocks[bi];
			v.resize(R - L);
			for(int i = L; i < R; ++ i)
				v[i - L] = make_pair(p[i], i);
			sort(v.begin(), v.end());
			for(int i = 0; i < R - L; ++ i)
				rankInBlock[v[i].second] = i;
		}
		int Q;
		scanf("%d", &Q);
		for(int ii = 0; ii < Q; ++ ii) {
			int l; int r;
			scanf("%d%d", &l, &r), -- l, -- r;
			int bl = (l + BlockSize - 1) / BlockSize, br = (r + 1) / BlockSize;
			long long ans = 0;
			if(bl > br) {
				ft.init(BlockSize);
				for(int i = r; i >= l; -- i) {
					ans += ft.sum(rankInBlock[i]);
					ft.add(rankInBlock[i], 1);
				}
			} else {
				int L = bl * BlockSize, R = br * BlockSize;
				ans += memo[bl][r];
				ans += memo[br][l];
				if(bl < br)
					ans -= memo[bl][R - 1];
				if(l < L && R <= r) {
					const vector<pair<int, int> > &v = sortedBlocks[bl - 1], &w = sortedBlocks[br];
					int nv = (int)v.size(), nw = (int)w.size();
					for(int i = 0, j = 0, cnt = 0; i < nv; ++ i) {
						for(; j < nw && w[j].first < v[i].first; ++ j)
							cnt += w[j].second <= r;
						if(l <= v[i].second)
							ans += cnt;
					}
				}
			}
			printf("%lld\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 160564
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	vector<int> A;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);
	}

	sort(A.begin(), A.end());

	cout << A[A.size() - 1] - A[0] << endl;
	
}


Measured memory_bytes: 3636
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans=0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if X == 500*a + 100*b + 50*c:
                ans+=1
print(ans)

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

int main(){
	int H,W,i,j;
	while(1){
		cin>> H>> W;
		if(H==0 && W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i+j)%2==0){
					cout<< "#";
				}
				else{
					cout<< ".";
				}
			}
		cout<< endl;
		}
	cout<< endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  ll k, n;
  cin >> k >> n;
  vl a(n);
  rep(i,n) cin >> a[i];
  
  ll mx = 0;
  rep(i,n-1) {
    chmax(mx, a[i+1]-a[i]);
  }
  chmax(mx, a[0]+k-a[n-1]);

  ll ans = k - mx;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1920
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

const MaxBuf = 200100
var buf []byte = make([]byte,MaxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf,MaxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r,_ := strconv.Atoi(sc.Text())
	return r
}

func readInt64() int64 {
	sc.Scan()
	r,_ := strconv.ParseInt(sc.Text(),10,64)
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r,_ := strconv.ParseFloat(sc.Text(),64)
	return r
}

func main() {

	i := 1
	for {
		x := readInt()
		if x == 0 {
			break
		}
		fmt.Printf("Case %d: %d\n",i , x)
		i++
	}

}


Measured memory_bytes: 1352
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int w,h;
int board[55][55];
int ans;

void dfs(int y,int x){
  board[y][x] =0;
  for(int i = -1;i <=1;i++){
    for(int j = -1;j <=1;j++){
      int ny =y + i;
      int nx =x + j;
      if(nx >=1&&nx <=w&&ny >=1&& ny <=h&&board[ny][nx] ==1){
	dfs(ny,nx);
      }
    }
  }
}

int main()
{
  
  while(cin>>w>>h,w||h){
    ans = 0;
    for(int i = 1;i <=h;i++){
      for(int j = 1;j <=w;j++){
	cin>>board[i][j];
      }
    }
    for(int i = 1; i <=h;i++){
      for(int j = 1;j <=w;j++){
	if(board[i][j] ==1){
	  ans++;
	  dfs(i,j);
	}
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}

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

int main()
{
	int val;
	vector<int> st;
	while (cin >> val) {
		if (val) {
			st.push_back(val);
		}
		else {
			cout << st.back() << endl;
			st.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 3012
use std::io::stdin;fn main() {let mut st = String::new();stdin().read_line(&mut st).unwrap();let x:Vec<i64> = st.trim().split(" ").map(|x| x.parse().unwrap()).collect();let y = x[2]-x[1];if y%2==0 {println!("Alice")} else {println!("Borys")}}

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

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto &e : s)
    cin >> e;

  bool flag = true;
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if (s[i][j] == '#')
      {
        if ((i > 0 && j > 0) && (s[i - 1][j] == '#' && s[i][j - 1] == '#'))
          flag = false;
        if ((i < h - 1 && j < w - 1) && (s[i + 1][j] == '#' && s[i][j + 1] == '#'))
          flag = false;
      }
    }
  }
  cout << (flag ? "Possible" : "Impossible") << endl;

  return 0;
}

Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n,m = map(int,input().split())
    print((n-1)*(m-1))
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 39916
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
ll fact[MAX],inverse[MAX];
ll Bigmod(int a,int b)
{
    if(b==0)
        return 1%MOD;
    ll x=Bigmod(a,b/2);
    x=(x*x)%MOD;
    if(b%2==1)
        x=(x*a)%MOD;
    return x;
}
ll nCr(int x, int y)
{
    if(x<0 || y<0 || x<y)
        return 0;
    return (fact[x] * (inverse[y] * inverse[x - y] % MOD)%MOD) % MOD;
}
void pre_cal()
{

    fact[0]=1;
    for(int i=1; i<=5000; i++)
        fact[i]=(fact[i-1]*1LL*i)%MOD;
    inverse[5000]=Bigmod(fact[5000],MOD-2);
    for(int i=5000; i>0; i--)
    {
        inverse[i-1]=(i* 1LL*inverse[i] )% MOD;
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,k;
    cin>>n>>k;
    int r=n-k;
    pre_cal();
    for(int i=1; i<=k; i++)
    {

        ll a=nCr(k-1,i-1);
        ll b=nCr(r+1,i);
        ll ans=(a*b)%MOD;

        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3740
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 2007;
const LD EPS = 1e-7;

int f_pos(int a, int b, int pos)
{
	LL x = max(a, b) / (min(a, b) + 1);
	if ((min(a, b) + 1) * x != max(a, b))
		++x;
	return min(x * (pos + 1), (a + 1) * x + pos - b) / (x + 1);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int q;
	cin >> q;
	REP(i, q)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		vector <int> A;
		string S;
		FOR(i, c - 1, d + 1)
			A.push_back(f_pos(a, b, i));
		FOR(i, 1, SZ(A))
			cout << (A[i] == A[i - 1] ? 'B' : 'A');
		cout << endl;
	}
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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 < a.length; i++) {
            a[i] = sc.nextInt();
        }
        
        for (int i = a.length - 1; i >= 0; i--) {
            if (i != 0) {
                System.out.printf("%d ", a[i]);
            }
            else {
                System.out.printf("%d\n", a[i]);
            }
        }
    }
}



Measured memory_bytes: 26796
package main
import (
    "fmt"
    "sort"
)

func main() {
    b := make([]int, 3)
    for i := 0; i < 3; i++ {
        fmt.Scan(&b[i])
    }
    sort.Ints(b)
    if b[2] == b[1]+b[0] {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}                             

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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=1001001001;
const long long mod=998244353;

int main(){
  int64_t N,X,M;
  cin>>N>>X>>M;
  vector<int>id(M,-1);
  vector<int>a;
  int len=0;
  int64_t tot=0;
  while(id[X]==-1){
    a.push_back(X);
    id[X]=len;
    len++;
    tot+=X;
    X=(X*X)%M;
  }
  int c=len-id[X];
  int64_t s=0;
  for(int i=id[X];i<len;i++){s+=a[i];}
  int64_t ans=0;
  if(N<=len){
    for(int i=0;i<N;i++){
      ans+=a[i];  
    }
  }
  else{//cout<<tot<<endl;
    ans+=tot;
    N-=len;
    ans+=s*(N/c);
    N%=c;
    for(int i=0;i<N;i++){
      ans+=a[id[X]+i];
    }
  }
  cout<<ans<<endl;
  return 0;                       
}

Measured memory_bytes: 4000
# coding: utf-8

# https://atcoder.jp/contests/abc112


def yakusu(n):
    ans = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            ans.append(i)
            if n // i != i:
                ans.append(n // i)
    
    return sorted(ans)


def main():
    N, M = map(int, input().split())
    
    xs = yakusu(M)

    for x in reversed(xs):
        if M // x >= N:
            return x


print(main())


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

int main(){
        ll N,A,B;
        cin >> N >> A >> B;
        ll ans = 0;

        ll sum = A + B;
        ans += A * (N  / sum);
        ans += min(N % sum, A);
        cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
#include <sstream>
#include <ctime>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mes(a, b) memset((a), (b), sizeof (a))
#define IosF ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;

struct Point{
    double x, y;
    Point(double a = 0, double b = 0) : x(a), y(b) {};
};

typedef Point Vector;
inline Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);}
inline Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);}
inline Vector operator * (Vector A, double x) {return Vector(A.x * x, A.y * x);}
inline Vector operator / (Vector A, double x) {return Vector(A.x / x, A.y / x);}
inline double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //向量点乘
inline double Len(Vector A) {return sqrt(Dot(A, A));}
inline double Ang(Vector A, Vector B) {return acos(Dot(A, B) / Len(A) / Len(B));} //向量夹角
inline double Cro(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //向量叉乘
inline double Area(Vector A, Vector B) {return Cro(A, B) * 0.5;} //组成三角形面积
inline Vector Rotate(Vector A, double rad) {return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));} //向量逆时针旋转角度rad
inline Vector Normal(Vector A) {double len = Len(A); return Vector(-A.y / len, A.x / len);}//求向量A的单位法线

typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6 + 10;
const int M = 0x3f3f3f3f;
const int inf = 0x7fffffff;
const int mod = 9901;
const double PI = acos(-1);

inline void Solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for ( int i = 0; i < n; i ++ ) cin >> a[i];
    sort(all(a));

    ll ans = a[n - 1];
    int num = 2;
    for ( int i = n - 2; i + 1; i -- ) {
        if ( num < n ) ans += a[i], num ++;
        if ( num < n ) ans += a[i], num ++;
    }

    cout << ans << endl;
}

int main() {
    IosF;
    Solve();
    return 0;
}


Measured memory_bytes: 4404
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	vector<string> S(3);
	for(int i=0; i<3; i++)
		cin >> S[i];
	
	int player = 0;
	while(S[player].empty() != true)
	{
		int next = S[player].front() - 'a';
		S[player] = S[player].substr(1, S[player].size());
		player = next;
	}

	char ret = 'A' + player;
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
import functools
import operator

def nCr(n, r):
    if n < r:
        return 0
    r = min(r, n-r)
    if r == 0:
        return 1
    num = functools.reduce(operator.mul, range(n, n-r, -1))
    den = functools.reduce(operator.mul, range(1, r+1))
    return num // den % mod

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

mod = 10**9 + 7
for i in range(1, k+1):
    print(nCr(k-1, i-1) * nCr(n-k+1, i) % mod)

Measured memory_bytes: 9580