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

int main(void){

	int n; 
	cin >> n;
	for (int t = 0; t < n; t++){

		int k, p;
		cin >> k >> p;

		int ret = k % p;

		if(ret !=0 )cout << ret << endl;
		else cout << p << endl;

	}


	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        string S;
        public bool[] F;
        public long ret;
        public void Run()
        {
            S = Console.ReadLine();
            N = S.Length;
            F = new bool[S.Length];
            DFSRun();
            Console.WriteLine(ret);
        }

        void DFSRun()
        {
            ret = 0;
            DFS(0);
        }

        void DFS(int i)
        {
            if (i == N - 1)
            {
                F[i] = true;
                ret += Calc();
            }
            else
            {
                F[i] = true;
                DFS(i + 1);
                F[i] = false;
                DFS(i + 1);
            }
        }

        public long Calc()
        {
            long ret = 0;
            int st = 0;
            for (int i = 0; i < N; i++)
            {
                if (F[i])
                {
                    int en = i + 1;
                    ret += long.Parse(S.Substring(st, en - st));
                    st = i + 1;
                }
            }

            return ret;
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11092
def main():
    h, w, k = map(int, input().split())
    grid = [list(input()) for _ in range(h)]
    ans = now = 0
    for now_h in range(pow(2, h)):
        for now_w in range(pow(2, w)):
            now = 0
            for i in range(h):
                for j in range(w):
                    if (now_h >> i) & 1 or (now_w >> j) & 1:
                        continue
                    elif grid[i][j] == "#":
                        now += 1
            if now == k:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()



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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

std::vector<int> zAlgorithm(const std::string& s) {
    int n = (int)s.size();
    if (n == 0) return {};

    std::vector<int> z(n);
    z[0] = 0;
    for (int i=1, j=0; i<n; ++i) {
        if (i + z[i-j] < j + z[j]) {
            z[i] = z[i-j];
        } else {
            int k = std::max(0, j + z[j] - i);
            while (i + k < n && s[i+k] == s[k]) ++k;
            z[i] = k;
            j = i;
        }
    }
    z[0] = n;

    return z;
}

int solve_i(int i, const string &S) {
    auto z = zAlgorithm(S.substr(i));
    int res = 0;
    for (int j=0; j<(int)z.size(); ++j) chmax(res, min(j, z[j]));
    return res;
}

void solve() {
    int N;
    string S;
    cin >> N >> S;

    int ans = 0;
    for (int i=0; i<N; ++i) chmax(ans, solve_i(i, S));
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3692
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ABC054DMixingExperiment solver = new ABC054DMixingExperiment();
    solver.solve(1, in, out);
    out.close();
  }

  static class ABC054DMixingExperiment {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int ma = in.nextInt();
      int mb = in.nextInt();
      int[] a = new int[n];
      int[] b = new int[n];
      int[] c = new int[n];
      // i個選んだ時にj,k(g)になるようなコスト
      int[][][] dp = new int[n + 1][401][401];

      for (int i = 0; i < n; i++) {
        a[i] = in.nextInt();
        b[i] = in.nextInt();
        c[i] = in.nextInt();
      }

      for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 401; j++) {
          for (int k = 0; k < 401; k++) {
            dp[i][j][k] = 1919810;
          }
        }
      }
      dp[0][0][0] = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < 401; j++) {
          for (int k = 0; k < 401; k++) {
            if (dp[i][j][k] == 114514) {
              continue;
            }
            int jj = j + a[i];
            int kk = k + b[i];
            if (jj > 400 || kk > 400) {
              continue;
            }
            dp[i + 1][j][k] = Math.min(dp[i][j][k], dp[i + 1][j][k]);
            dp[i + 1][jj][kk] = Math.min(dp[i + 1][jj][kk], dp[i][j][k] + c[i]);
          }
        }
      }

      int res = (int) 1e9;
      int cnt = 1;
      while (true) {
        if (Math.max(cnt * ma, cnt * mb) > 400) {
          break;
        }
        res = Math.min(res, dp[n][cnt * ma][cnt * mb]);
        cnt++;
      }
      if (res >= 1919810) {
        res = -1;
      }

      out.println(res);


    }

  }
}



Measured memory_bytes: 54484
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		long a = nl();
		long b = nl();

		System.out.println(lcm(a,b));

	}

	//Find greatest common divisor
	static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a%b) : a;
	}
	//Find least common multiple
	static long lcm (long a, long b) {
		return a * b / gcd(a, b);
	}
	//Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;


template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 100005
#define mod 1000000007

const int inf = 1e9+5;

int main(int argc, const char * argv[]) {
     
    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();
        
    int n, k;
    cin >> n >> k;
    vi info(n);
    for(auto &i : info){
    	cin >> i;
    }
    vi dp(n+1,inf);
    dp[1] = 0;
    for(int i = 1; i<=n; i++){
    	for(int j = i+1; j<=n && j<=i+k;j++){
    		dp[j] = min(dp[j], dp[i] + abs(info[i-1]-info[j-1]));
    	}
    }

    print(dp[n]);

    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

        
    return 0;
}





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

using namespace std;

// ABC104-B - AcCepted
int main()
{
    string S;
    cin >> S;

    string ans = "AC";

    if (S[0] != 'A') ans = "WA";
    else {
        int cnt = 0;
        int index;
        for (int i = 2; i < S.length() - 1; i++) {
            if (S[i] == 'C') {
                cnt++;
                index = i;
            }
        }
        if (cnt != 1) ans ="WA";
        else {
            for (int i = 1; i < S.length(); i++) {
                if (i == index) continue;
                if (S[i] < 'a' || S[i] > 'z') {
                    ans = "WA";
                    break;
                }
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}


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

//////全探索したいときに開けよ////////
/*
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}
*/

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t h,w,n;
  cin >> h;
  cin >> w;
  cin >> n;
  int64_t maxp = max(h,w);
  cout << (n + maxp -1)/maxp << endl;
}

Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = 'APPROVED'
no = 'DENIED'

def main():
    n = ii()
    s = []
    for i in range(n):
        tmp = input()
        s.append(tmp)
    
    s = sorted(s)

    anslist = []

    cnt = 0
    cntmax = 0
    tmp = ""
    for i in range(n):
        if cntmax == 0:
            anslist.append(s[i])
        if s[i] == tmp:
            cnt+=1
            if cntmax == cnt:
                anslist.append(s[i])
            if cntmax < cnt:
                cntmax = cnt
                anslist = [s[i]]
        else:
            cnt = 0
            tmp = s[i]
    for i in range(len(anslist)):
        print(anslist[i])



main()



Measured memory_bytes: 22220
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int a, b;
	while (cin >> a >> b, a | b)
	{
		int s = b - a;
		int v[] = { 100, 500, 1000 };
		int res[3];
		for (int i = 2; i >= 0; --i)
		{
			int t = s / v[i];
			s -= t * v[i];
			res[i] = t;
		}
		printf("%d %d %d\n", res[0], res[1], res[2]);
	}
}

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

int N,W;
int A[1005];

int dp[1005];
const int INF = 1000000009;
void update(int &a,int b){ a = min( a, b ); }
int solve(){
  fill( dp, dp+N+1, INF );
  dp[0] = 0;
  for(int i=0;i<N;i++){
    int sum = 0;
    for(int j=i;j<N;j++){
      sum += A[j];
      if( j+1 < N )
        update( dp[j+1], dp[i] + abs( sum-W ) );
      else
        update( dp[j+1], dp[i] + max( 0, sum-W ) );
    }
  }
  return dp[N];
}
int main(){
  int ttt=0;
  while( cin >> N >> W &&(N|W) ){
    for(int i=0;i<N;i++)
      cin >> A[i];
    cout << "Case " <<  ++ttt<< ": ";
    cout << solve() << endl;   
  }
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a>c){
    swap(a,c);
  }
  if(d>b){
    swap(b,d);
  }
  int ans=d-c;
  if(d-c>=0){
    cout<<ans<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

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

using namespace std;
typedef long long ll;
typedef pair<int,ll>pa;

const int N=2e5+100;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int d[300][300];
int a[10];
int n,m,r;
void floyd()
{
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            if(d[i][k]!=inf)
            for(int j=1;j<=n;j++){
                d[i][j]=min(d[i][k]+d[k][j],d[i][j]);
            }
        }
    }
}
ll slove()
{
    ll ans=0;
     for(int i=1;i<r;i++){
     ans+=d[a[i]][a[i+1]];
   }
   return ans;
}
int main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   cin>>n>>m>>r;
   for(int i=1;i<=r;i++)
    cin>>a[i];
   memset(d,0x3f,sizeof d);
   for(int i=1;i<=m;i++){
       int a,b,c;
       cin>>a>>b>>c;
       d[a][b]=d[b][a]=c;
   }
   floyd();
   ll ans=1e18;
   sort(a+1,a+1+r);
   do{
      ans=min(ans,slove());
   }while(next_permutation(a+1,a+1+r));

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



Measured memory_bytes: 4000
///*
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {

	bool dontsay = true, shiritori = true;
	int number;
	string *words;

	cin >> number;
	words = new string[number];

	for (int i = 0; i < number; i++) {
		cin >> words[i];
		if (i != 0 && words[i - 1][words[i-1].length()-1] != words[i][0]) {
			shiritori = false;
		}
	}

	sort(words, words + number);

	for (int i = 0; i < number - 1; i++) {
		if (words[i] == words[i + 1]) {
			dontsay = false;
		}
	}

	if (dontsay&&shiritori) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	delete[]words;
	return 0;
}
//*/

Measured memory_bytes: 256
N = int(input())
S = input()
cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            idx = 0
            a = S.find(str(k),idx)
            if a != -1:
                idx = a
                b = S.find(str(j),idx+1)
                if b != -1:
                    idx = b
                    c = S.find(str(i),idx+1)
                    if c != -1:
                        cnt += 1

print(cnt)

Measured memory_bytes: 3188
// 15:08 - 15:34

#include <iostream>
#include <cmath>

using namespace std;

int main(void) {

	long long x, y;
	cin >> x >> y;

	long long a, b;
	a = min(x, y);
	b = max(x, y);

	if (b - a > 1) {
		cout << "Alice" << endl;
	} else {
		cout << "Brown" << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <functional>
#include <string>
#include <cstring>
#include <sstream>
#include <deque>
#define fir first
#define sec second
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> Q;

const int inf1=1e9+9;
const ll inf2=8e18+9;
const ll mol=1e9+7;
const int maxn=2e3+9;
const ll maxx=1e12+9;



int main()
{
    int n,k,ar[maxn];
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>ar[i];
    int sum=0;
    sort(ar,ar+n);
    for(int i=0;i<k;i++) sum+=ar[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 3196
k = gets.to_i
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
puts arr[k-1]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int n, m;
  cin >> n >> m;
  int k;
  vec1 c(m);
  for(int i = 0; i < n; i++) {
    cin >> k;
    for(int j = 0; j < k; j++) {
      int a;
      cin >> a;
      c.at(a-1)++;
    }
  }
  int ans = 0;
  for(int i = 0; i < m; i++) {
    if(c.at(i) == n) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

//Shortcut
#define long long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define X first
#define Y second
#define sz size
#define ft(i , a , b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i , a , b) for (long i = (long)a ; i >= (long)b ; i--)
#define lt(i , a , b , c) for (long i = (long)a ; i <= (long)b ; i += (long)c)
#define ld(i , a , b , c) for (long i = (long)a ; i >= (long)b ; i -= (long)c)
#define pll pair <long , long>
#define pls pair <long , string>
#define vtl vector <long>
#define vts vector <string>
#define vtp vector <pll>
#define dql deque <long>
#define mll map <long , long>
#define prio priority_queue<pll , vector<pll > , greater<pll> >
#define pushpq(a , b) push({(long) a , (long) b})

//Variable
const long mxN = 1e3 + 5;
const long base = 311;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const long d4i[4] = {-1 , 0 , 1 , 0} , d4j[4] = {0 , 1 , 0 , -1};
const long d8i[8] = {-1 , -1 , 0 , 1 , 1 , 1 , 0 , -1} , d8j[8] = {0 , 1 , 1 , 1 , 0 , -1 , -1 , -1};

long TestCase;
long n , m; 
long a[mxN][mxN] , dp[mxN][mxN];
char c;

void Solve() {
    cin >> n >> m;
    ft(i , 1 , n) 
    ft(j , 1 , m) {
        cin >> c;
        if (c == '.') a[i][j] = 1;
    }
    dp[1][1] = 1;
    ft(i , 1 , n) {
        ft(j , 1 , m) {
            if (a[i + 1][j]) dp[i + 1][j] += dp[i][j];
            if (a[i][j + 1]) dp[i][j + 1] += dp[i][j];
            dp[i + 1][j] %= MOD;
            dp[i][j + 1] %= MOD;
        }
    }
    cout << dp[n][m];
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    //cin >> TestCase;
    TestCase = 1;
    while(TestCase--)
        Solve();
    return 0;
}

Measured memory_bytes: 19308
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 100;
char str[N];
int a, b;
int main()
{
    bool t1 = true;
    scanf("%d%d", &a, &b);
    scanf("%s", str);
    int t = strlen(str);
    if(t!=a+b+1)
    {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < a+b+1;i++)
    {
        if(i==a)
            {
                if(str[a]!='-')
                    t1 = false;
            }
        else
        {
            if(str[i]=='-')
                t1 = false;
        }
    }
    if(t1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main()
{
    int n;
    string s;
    vector<int> v;

    while( cin >> s )
    {
        if( s == "insert" )
        {
            cin >> n;
            v.push_back(n);
            int i = v.size() - 1;
            while( i != 0 && v[i] > v[(i-1)/2] )
            {
                int temp = v[i];
                v[i] = v[(i-1)/2];
                v[(i-1)/2] = temp;
                i = ( i - 1 ) / 2;
            }
        }
        else if( s == "extract" )
        {
            cout << v[0] << endl;
            v[0] = -1;
            int i = 0;
            while( i * 2 + 1 < v.size() && v[i] < v[i*2+1] || i * 2 + 2 < v.size() && v[i] < v[i*2+2] )
            {
                int j;
                if( i * 2 + 2 < v.size() )
                    j = v[i*2+1] > v[i*2+2] ? i*2+1 : i*2+2;
                else
                    j = i * 2 + 1;
                int temp = v[i];
                v[i] = v[j];
                v[j] = temp;
                i = j;
            }
        }
        else
            break;
    }
    return 0;
}


Measured memory_bytes: 11216
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2*1e5+7;
#define ll long long
ll dp[5*MAXN];
ll tree[5*MAXN];
ll h[MAXN];
ll a[MAXN];
ll N;

ll query(ll node, ll start, ll end, ll l, ll r)
{
    if(r < start or end < l)
    {
        return 0;
    }
    if(l <= start and end <= r)
    {
        return tree[node];
    }
    ll mid = (start + end) / 2;
    ll p1 = query(2*node, start, mid, l, r);
    ll p2 = query(2*node+1, mid+1, end, l, r);
    return max(p1 , p2);
}

void update(ll node, ll start, ll end, ll idx, ll val)
{
    if(start == end)
    {
        //A[idx] = max(val,A[idx]);
        tree[node] = max(val,tree[node]);
    }
    else
    {
        ll mid = (start + end) / 2;
        if(start <= idx and idx <= mid)
        {
            update(2*node, start, mid, idx, val);
        }
        else
        {
            update(2*node+1, mid+1, end, idx, val);
        }
        tree[node] = max(tree[2*node] ,tree[2*node+1]);
    }
}


int main()
{
    cin>>N;
    for(int i=0;i<N;i++)
    {
        cin>>h[i];
        
    }
    for(int i=0;i<N;i++)
    cin>>a[i];
    for(int i=0;i<N;i++)
    {
        ll x=h[i];
        dp[i]=query(1,1,500000,1,x)+a[i];
        update(1,1,500000,x,dp[i]);
    }
    ll maxi=0;
    for(int i=0;i<N;i++)
    maxi=max(maxi,dp[i]);
    cout<<maxi<<"\n";
}

Measured memory_bytes: 14592
#include <iostream>
#include <stdio.h>

#include <vector>

using namespace std;

int main()
{
    int x, y, n, m, l;
    cin >> n >> m >> l;

    vector<vector<int> > a(n, vector<int>(m));

    vector<vector<int> > b(m, vector<int>(l));

    vector<vector<long long> > c(n, vector<long long>(l)) ;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> x;
            a[i][j] = x;
        }
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> y;
            b[i][j] = y;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l;j++) {
            c[i][j] = 0;
            for (int h = 0; h < m; h++) {
                c[i][j] = c[i][j] + a[i][h] * b[h][j];
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            cout << c[i][j];
            if (j != l - 1) {
                cout << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3288
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, X, Y = list(map(int, sys.stdin.readline().split()))

# そのまま買う
a1 = A * X + B * Y
# AB だけ使う
a2 = C * max(X, Y) * 2
# 少ない方に AB を使う
a3 = C * min(X, Y) * 2
if X > Y:
    a3 += A * (X - Y)
else:
    a3 += B * (Y - X)

print(min(a1, a2, a3))



Measured memory_bytes: 14384
#include <stdio.h>
int main(void){
    // Your code here!
    int k, tmp = 7, i, mod = 0;
    scanf("%d", &k);
    for (i = 0; i < k * 2; i++)
    {
        mod = (mod + tmp)%k;
        tmp = (tmp * 10)%k;
        if (!mod)
        {
            printf("%d", i + 1);
            return (0);
        }
    }
    printf("-1");
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> s >> t;
    if (s < t) MSG("<")
    else if (s > t) MSG(">")
    else MSG("=")
}


Measured memory_bytes: 256
from itertools import product
h,w,k = map(int, input().split())
hw = [[0 for j in range(w)] for i in range(h)]
total = 0
htotal = [0 for i in range(h)]
wtotal = [0 for i in range(w)]

for i in range(h):
	line = [s for s in input()]
	for j in range(len(line)):
		if line[j]=='#':
			hw[i][j]=1
	htotal[i]=sum(hw[i])
for i in range(w):
	res=0
	for j in range(h):
		if hw[j][i]:
			res+=1
	wtotal[i]=res
total = sum(htotal)
#print(hw)
#print(total,htotal, wtotal)
ans = 0
for bit in product(range(2),repeat=w+h):
	wbit=bit[:w]
	hbit=bit[w:]
	res=0
	for i,v in enumerate(wbit):
		if v:res-=wtotal[i]
	for i,v in enumerate(hbit):
		if v:res-=htotal[i]
	#print(res)
	for i,hv in enumerate(hbit):
		if hv:
			for j,wv in enumerate(wbit):
				if wv:
					if hw[i][j]:
						res+=1
	#print('---', total,res,k)
	if total+res==k:
		ans+=1
		#print('bit', bit)
print(ans)

Measured memory_bytes: 9068
w, h, n = map(int, input().split())

list_state = [list(map(int, input().split())) for i in range(n)]

max_x = w
max_y = h
min_x = 0
min_y = 0

for i in list_state:
    if i[2] == 1 and min_x < i[0]:
        min_x = i[0]
    if i[2] == 2 and max_x > i[0]:
        max_x = i[0]
    if i[2] == 3 and min_y < i[1]:
        min_y = i[1]
    if i[2] == 4 and max_y > i[1]:
        max_y = i[1]

x = max_x - min_x
y = max_y - min_y

if x > 0 and y > 0:
    print(x*y)
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());


int main() {
  ll n;
  cin >> n;
  vector<ll> a(n),b(n);
  REP(i,n) {
    cin >> a[i];
    b[i]=a[i];
  }
  sort(ALL(a));
  REP(i,n) {
    if(b[i]!=a[n-1]) {
      cout << a[n-1] << endl;
    } else {
      cout << a[n-2] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);



int main() {
    ll n;
    cin>>n;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    if(n==1){
        cout<<1<<endl;return 0;
    }


    map<pair<ll,ll>,ll> m;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ll a=v[j].first-v[i].first;
            ll b=v[j].second-v[i].second;
            pair<ll,ll> pp={a,b};
            pair<ll,ll> p2={-a,-b};
            m[pp]++;
            m[p2]++;
        }
    }

    ll ans=0;
    for(auto &&a:m){
       // cout<<a.first.first<<a.first.second<<a.second<<endl;
        if(a.second>ans){
            ans=a.second;
        }
    }


    cout<<n-ans<<endl;










    return 0;
}


Measured memory_bytes: 384
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;
}   

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i,n) for(ll i=0; i<(n); i++)
#define forn for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

void min_self(int &a, int b){
	a = min(a, b);
}
void max_self(int &a, int b){
	a = min(a,b);
}

const int INF = 1e9 + 5;

void solve(){
	int n, w;
	cin >> n >> w;
	vi wt(n), vl(n);
	forn{
		cin >> wt[i] >> vl[i];
	}
	vll dp(w + 1, 0);
	forn{
		for(int weight=w - wt[i]; ~weight; --weight){
			chmax(dp[weight+wt[i]], dp[weight]+vl[i]);
		}
	}
	cout << dp[w] << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
    return 0;
}

Measured memory_bytes: 1024
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,X,Y,Z = inpl()
x = sorted(inpl())
y = sorted(inpl())
c = sorted(inpl())
c = c[::-1]
res = sum(x[X-a:]) + sum(y[Y-b:])
x += [INF]; y += [INF]
i = X-a; j = Y-b
ind = 0
iok = True; jok = True
while ind < Z:
    if x[i] <= y[j]:
        if x[i] < c[ind]:
            res += c[ind] - x[i]
            ind += 1
            i += 1
        else:
            break
    else:
        if y[j] < c[ind]:
            res += c[ind] - y[j]
            ind += 1
            j += 1
        else:
            break
    # print(i,j,ind)
print(res)

Measured memory_bytes: 124300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


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

    ll max_cnt = 0;

    REP(i,n-1){
        ll cnt = 0;
        string tmp1 = s.substr(0, i + 1);
        string tmp2 = s.substr(i + 1);
        set<char> set1;
        set<char> set2;
        REP(j,tmp1.size()){
            set1.insert(tmp1[j]);
        }
        REP(j,tmp2.size()){
            set2.insert(tmp2[j]);
        }

        for (auto itr = set1.begin(); itr != set1.end();itr++){
            if(set2.find(*itr) != set2.end()){
                cnt++;
            }
        }

        if(max_cnt <= cnt){
            max_cnt = cnt;
        }
    }

    cout << max_cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

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

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

    int r = a[0];
    for(int i = 1; i < n; i++){
        r = gcd(r, a[i]);
    }

    cout << r << endl;
    
    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	bool flag = false;

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (N == i*j)
				flag = true;
		}
	}

	if (flag)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		System.out.println(a + b > c + d ? "Left" : a + b == c + d ? "Balanced" : "Right");
		sc.close();
	}

}


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

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

fn main() {
    let n = read::<usize>();
    let mut x = vec![0; n];
    let mut y = vec![0; n];

    for i in 0..n {
        x[i] = read::<i64>();
        y[i] = x[i];
    }
    x.sort();

    let m = x[(n as i32/2 - 1) as usize];
    let mm = x[(n as i32/2) as usize];
    for i in 0..n {
        if y[i] > m {
            println!("{}", m);
        } else {
            println!("{}", mm)
        }
    }
}

Measured memory_bytes: 10364
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

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

    if (a + b >= c) {
        cout << "Yes"<< endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 888
#include<stdio.h>
  
int main(){
  int r,w,i,j,y=0,f,g,h;
  scanf("%d",&r);
  int a[r];
  char b[12];
 
  for(i=0;i<r;i++){
    scanf("%s %d",b,&w);
 
    if(b[0]=='i'){
      a[i]=w;
    }
 
    else if(b[6]=='F'){
      i-=2;r-=2;
    }
 
    else if(b[6]=='L'){
      i--;r--;y++;
    }
 
    else{
      i--;r--;
      f=0;
      for(j=i;j>=0;j--){
 
    if(f>0)break;
 
    if(w==a[j]){
      h=0;
      g=i-j;
      f++;
      while(g!=h++)a[j+h-1]=a[j+1+h-1];
      i--;r--;
    }
      }
    }
  }
  for(i=0;i<r-y;i++){
    if(i==r-y-1)printf("%d\n",a[r-1-i]);
    else printf("%d ",a[r-1-i]);
  }
  return 0;
}

Measured memory_bytes: 4952
#include <stdio.h>
#include <math.h>
#include <climits>

int main() {
    int H, W;
    int c[10][10];
    scanf("%d %d", &H, &W);
    int A[H][W];
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            scanf("%d", &c[i][j]);
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%d", &A[i][j]);
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] != -1 && A[i][j] != 1) {

                int a = A[i][j];
                bool done[9];
                int cost[9];
                for (int i = 0; i < 10; i++) {
                    done[i] = false;
                    cost[i] = INT_MAX;
                }
                cost[a] = 0;

                int count = 0;

                while (count <= 10) {
                    int min = INT_MAX;
                    int node_num;
                    for (int i = 0; i < 10; i++) {
                        if (!done[i] && min >= cost[i]) {
                            min = cost[i];
                            node_num = i;
                        }
                    }
                    // printf("node_num = %d  cost = %d\n", node_num, cost[node_num]);
                    if (node_num == 1) {
                        break;
                    }
                    done[node_num] = true;
                    count++;
                    for (int j = 0; j < 10; j++) {
                        int _cost = cost[node_num] + c[node_num][j];
                        // printf("%d<%d c:%d\n", _cost, cost[j], c[node_num][j]);
                        if (_cost < cost[j]) {
                            cost[j] = _cost;
                        }
                    }
                }
                // printf("cost = %d\n", cost[1]);
                ans += cost[1];
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    x,y,z,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ab = []
    for i in a:
        for j in b:
            ab.append(i+j)
    ab.sort(reverse=1)
    ab = ab[:k]
    abc = []
    for i in ab:
        for j in c:
            abc.append(i+j)
    abc.sort(reverse=1)
    for i in range(k):
        print(abc[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 139652
#include <iostream>
#include <vector>

using namespace std;

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

Measured memory_bytes: 3068
////////////////いろいろあるよ//////////////////////////////////
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream>
 #include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
   string A,B;
	int a,b;
	cin >> A >> B >>a >>b;
  string hoge;
  cin >>hoge;
  if(hoge==A)cout << a-1 << " " << b << endl;
  else cout << a << " " << b-1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

N,K = LI()
R,S,P = LI()
T = list(input())
hand = []

def main():
    ans = 0
    for i in range(N):
        if T[i] == 's':
            if i<K or hand[i-K]!='r':
                ans += R
                hand.append('r')
            else:
                hand.append('x')
        if T[i] == 'p':
            if i<K or hand[i-K] != 's':
                ans += S
                hand.append('s')
            else:
                hand.append('x')
        if T[i] == 'r':
            if i<K or hand[i-K] != 'p':
                ans += P
                hand.append('p')
            else:
                hand.append('x')
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 51596
let solve a b c =
  let rec aux i =
    let m = (a * i) mod b in
    match m, c with
    | 0, 0 -> "YES"
    | 0, _ -> "NO"
    | m, c when m = c -> "YES"
    | _ -> aux (succ i) 
  in
  aux 1

let () = Scanf.scanf "%d %d %d" solve |> print_endline

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
   ll n,q,i,a,b,c;
   cin>>n;
   map<ll,ll> m;
   ll sum=0;
   for(i=0;i<n;i++){
       cin>>a;
       sum+=a;
       m[a]++;
   }
   cin>>q;
   while(q--){
       cin>>b>>c;
       sum+=m[b]*c;
       sum-=m[b]*b;
       m[c]+=m[b];
       m[b]=0;
       cout<<sum<<"\n";
   }
	
	return 0;
}

Measured memory_bytes: 9540
#include<stdio.h>
int main()
{
    int h,w;
    scanf("%d%d",&h,&w);
    char a[100][100];
    for(int i=1; i<=h; i++)
    {
        getchar();
        for(int j=1; j<=w; j++)
            scanf("%c",&a[i][j]);
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            if(a[i][j]=='.')
            {
                int flag=0;
                if(a[i-1][j]=='#')
                    flag++;
                if(a[i][j-1]=='#')
                    flag++;
                if(a[i-1][j-1]=='#')
                    flag++;
                if(a[i+1][j]=='#')
                    flag++;
                if(a[i][j+1]=='#')
                    flag++;
                if(a[i+1][j+1]=='#')
                    flag++;
                if(a[i-1][j+1]=='#')
                    flag++;
                if(a[i+1][j-1]=='#')
                    flag++;
                a[i][j]=flag+48;
            }
        }
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
            printf("%c",a[i][j]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < D; j++){
            cin >> X.at(i).at(j);
        }
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < i; j++) {
            double dist = 0;
            for(int k = 0; k < D; k++) {
                dist += pow((X.at(i).at(k) - X.at(j).at(k)), 2);
            }
            if(pow(dist, 0.5) == (int)pow(dist, 0.5))  ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int[] a = new int[n];
        int[] b = new int[1000001];
        Arrays.fill(b,0);
        int ans = 0;
        for(int i=0;i<n;i++){
            a[i]=scn.nextInt();
        }

        for(int i=0;i<n;i++){
            if(b[a[i]]!=0){
                b[a[i]]=2;
                continue;
            }
            for(int j=a[i];j<1000001;j+=a[i]){
                b[j]++;
            }
        }
        for (int i=0;i<n;i++) {
            if (b[a[i]]==1) ans++;
        }

        System.out.println(ans);
     scn.close();

    }

}

Measured memory_bytes: 53800
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [r] = [int(input_raw[0])]
    print 3 * r * r

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932