akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
int main(){
	char b;
	cin >> b;

	if (b == 'A')cout << "T" << endl;
	if (b == 'T')cout << "A" << endl;
	if (b == 'C')cout << "G" << endl;
	if (b == 'G')cout << "C" << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
H.reverse()
for i in range(N - 1):
    if H[i + 1] > H[i]:
        H[i + 1] -= 1
        if H[i + 1] > H[i]:
            print("No")
            exit()

print("Yes")


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

int main(){
	ll n,ans=0; cin >> n;
	vint a(n);
	rep(i,n) cin >> a[i];
	ll nowmax=a[0];
	for(int i=1;i<n;i++) {
		if(a[i]<=nowmax) ans+=nowmax-a[i];
		else nowmax=a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3956
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $x = <STDIN>);
my $ans = 0;
$ans = int($x/500)*1000;
$x -= int($x/500)*500;
$ans += int($x/5)*5;
say $ans;

Measured memory_bytes: 768
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val in = new Scanner(System.in)
  val V = in.nextInt()
  val E = in.nextInt()
  val dinitz = new Dinitz(V)
  for (_ <- 0 until E) {
    val s = in.nextInt()
    val t = in.nextInt()
    val c = in.nextInt()
    dinitz.addEdge(s, t, c)
  }

  val f = dinitz.maxFlow(0, V - 1)
  println(f)
}

import java.util

class Dinitz(val V: Int) {

  class Edge(var to: Int, var cap: Long, var rev: Int)

  private val graph = (for (_ <- 0 until V) yield new ArrayBuffer[Edge]()).toArray
  private var level = new Array[Int](V)
  private var iter = new Array[Int](V)


  def addEdge(from: Int, to: Int, cap: Long): Unit = {
    graph(from).append(new Edge(to, cap, graph(to).size))
    graph(to).append(new Edge(from, 0, graph(from).size - 1))
  }

  private def dfs(v: Int, t: Int, f: Long): Long = {
    if (v == t) return f

    while (iter(v) < graph(v).size) {
      val e = graph(v)(iter(v))
      if (e.cap > 0 && level(v) < level(e.to)) {
        val d = dfs(e.to, t, Math.min(f, e.cap))
        if (d > 0) {
          e.cap -= d
          graph(e.to)(e.rev).cap += d
          return d
        }
      }

      {
        iter(v) += 1
        iter(v) - 1
      }
    }
    0
  }

  private def bfs(s: Int): Unit = {
    val queue=new mutable.Queue[Int]()
    util.Arrays.fill(level, -1)
    level(s) = 0
    queue.enqueue(s)
    while (queue.nonEmpty) {
      val v = queue.dequeue()
      for (e <- graph(v)) {
        if (e.cap > 0 && level(e.to) < 0) {
          level(e.to) = level(v) + 1
          queue.enqueue(e.to)
        }
      }
    }
  }

  def maxFlow(s: Int, t: Int): Long = {
    var flow = 0L

    while (true) {
      bfs(s)
      if (level(t) < 0) return flow
      util.Arrays.fill(iter, 0)

      var f = 1L
      while (f > 0) {
        f = dfs(s, t, Long.MaxValue)
        flow += f
      }
    }

    throw new IllegalStateException()
  }
}

Measured memory_bytes: 52168
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=104;
char ss[N];
int n,ans;
int main() {
	scanf("%s",ss+1);
	n=strlen(ss+1);
	for (int i=1;(i<<1)<=n;++i)
		ans+=bool(ss[i]^ss[n-i+1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int A, B;
  cin >> A >> B;
  for (double i = 1; i <= 100000; i++) {
    int low = i * 0.08;
    int high= i * 0.1;
    if (low == A && high == B) {
      cout << i << endl;
      return 0;
    } else if (low > A || high > B) {
      break;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from math import sqrt
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A =[[int(_) for _ in input().split()] for i in range(n)]
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)
    print(ans*2/n)
if __name__=='__main__':
    main()

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INF = 2147483647;
const long long LINF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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(void){
    string S; cin >> S;
    REVERSE(S); S += '0';
    int N = S.size();
    int ans = 0;
    bool flag = false;
    REP(i,N){
        int x = S[i]-'0';
        if(flag) x++;
        flag = false;
        if(x < 5) ans += x;
        else if(5 < x){
            ans += 10 - x;
            flag = true;
        }
        else{
            if(S[i+1]-'0' < 5) ans += x;
            else{
                ans += 10 - x;
                flag = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
#include <stdio.h>
#include <stdlib.h>

int main()
{
  char s[105];
  int i;
  char c[5];
  scanf("%s", s);
  for(i = 0; *(s+i) != '\0'; i++){
  }

  sprintf(c, "%c%d%c", s[0], i-2, s[i-1]);

  printf("%s\n", c);
  
  return 0;
}
  
  


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S,T; cin >> S >> T;
    for (char c = 'a'; c <= 'z'; c++) {
        string U = S;
        U += c;
        if (U==T) {
            cout << "Yes" << ln;
            return 0;
        }
    }
    cout << "No" << ln;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <math.h>

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

typedef long long ll;

const ll INF = 1e9+7;

using namespace std;

int main(){
  
  int N,D;
  cin>>N>>D;
  vector<vector<int> > X(N, vector<int>(D));
  rep(i,N){
    rep(j,D){
      cin>>X[i][j];
    }
  }
  int ans = 0;
  for(int i = 0;i < N;i++){
    for(int k = i + 1;k < N;k++){
      int tmp = 0;
      for(int j = 0;j < D;j++){
        int temp = X[i][j] - X[k][j];
        temp *= temp;
        tmp += temp;
      }
      double sq = sqrt((double)tmp);
      if(fmod(sq,1.0) == 0)ans++;
    }
  }
  print(ans)
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y,z;
	cin >> x;
      cout << 48-x << endl;
}

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

int main(void){
    int h;
    cin >> h;
    int w;
    cin >> w;

    vector<string> a(h);
    for(int i = 0; i < h; i++){
        cin >> a.at(i);
    }

    vector<bool> row(h, false);
    vector<bool> col(w, false);

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a.at(i).at(j) == '#'){
                row.at(i) = true;
                col.at(j) = true;
            }
        }
    }

    for(int i = 0; i < h; i++){
        if(row.at(i)){
            for(int j = 0; j < w; j++){
                if(col.at(j)){
                    cout << a.at(i).at(j);
                }
            }
            cout << endl;
        }
    }  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll a;
    string s;
    cin >> a >> s;

    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }

    return 0;
}


Measured memory_bytes: 3576
import scala.io.StdIn.readLine

object Main {
  def f(i:Int) = if(i<0) 15+i else i
  def getIndex(s:String) = s match {
    case "Rock" => 0 case "Fire" => 1 case "Scissors" => 2 case "Snake" => 3
    case "Human" => 4 case "Tree" => 5 case "Wolf" => 6 case "Sponge" => 7
    case "Paper" => 8 case "Air" => 9 case "Water" => 10 case "Dragon" => 11
    case "Devil" => 12 case "Lightning" => 13 case "Gun" => 14
  }
  val gestures = Array("Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun")
  def main(args:Array[String]) = {
    var n = 0
    while({n=readLine.trim.toInt;n}!=0) {
      val list = {for(i<-1 to n) yield getIndex(readLine.trim)}.toArray.sorted
      var flg = -1
      for(i <- 0 until n) {
        val win = f(list((i+1)%n)-list(i))
        val lose = f(list(i)-list(if(i>0) i-1 else n-1))
        if(win<=7 && lose>7) flg=list(i)
      }
      if(flg == -1) println("Draw")
      else
        println(gestures(flg))
    }
  }
}

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

#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fr freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define mp make_pair
#define F first
#define S second

using namespace std;

const int N = 5e5 + 2;
const int mod = 1e9 + 7;

ll gcd (ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}
ll lcm (ll a, ll b) {
	return a / gcd (a, b) * b;
}
int main () {
	speed;
	ll a,b;
	cin>>a>>b;
	cout<<lcm(a,b);
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            if (map.containsKey(a)) {
                map.put(a, map.get(a) + 1);
            } else {
                map.put(a, 1);
            }
        }
        sc.close();

        // 主処理
        int result = 0;
        for (int key : map.keySet()) {
            int count = map.get(key);
            int num = 0;
            if (key <= count) {
                num = count - key;
            } else {
                num = count;
            }
            result += num;
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 46880
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define CHKR
#define ll long long
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define ARRS int(2e5+500)
#define BARRS int(6e4+600)
#define MAX ((int)(2e9+15))
#define EP ((double)(1e-12))
#define MMAX ((long long)(1e9+10))
#define HS1 ((long long)(1000001329))
#define HS2 ((long long)(1000001531))
#define MOD ((long long)1000000000ll)
#define SQ 31622780
#define PI 3.14159265358979323846264338327950288419716939937510
#define BG 4294967232ll
#define MH 200008
ll a[ARRS];

#ifndef CHKR
int main(){
#else
int doit(fstream &in,fstream &out){
    cin.rdbuf(in.rdbuf());
    //cout.rdbuf(out.rdbuf());
#endif
    #ifdef KHOKHO
        #ifndef CHKR
        freopen("in.in","r",stdin);
        freopen("out.out","w+",stdout);
        #endif //CHKR
    #endif //KHOKHO
    ll n,m,k,d=MAX;
    string s;
    cin>>n;
    for(int i=0; i<n; i++){
		cin>>a[i];
    }
    sort(a,a+n);
    if(a[0]+1<a[n-1]){
		cout<<"No";
		return 0;
    }
    if(a[0]==a[n-1]){
		if(a[0]==n-1){
			cout<<"Yes";
			return 0;
		}
		if(a[0]*2>n){
			cout<<"No";
		}
		else cout<<"Yes";
		return 0;
    }
    ll t;
    for(int i=0; i<n; i++){
		if(a[i]!=a[0]){t=i;break;}
    }
    //cout<<t<<endl;
    if(a[n-1]>t&&(a[n-1]-t)*2+t<=n){
		cout<<"Yes";
    }
    else cout<<"No";



    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

long getFactorial(int number)
{

    long ans = 1;
    if (number == 0)
    {
        ans = 0;
    }
    else
    {
        while (number > 0)
        {
            ans = ans * number;
            number--;
        }
    }

    return ans;
}

int main(void)
{

    int i_inputPermutationSize;
    int ia_inputFirstPermutation[8];
    int ia_inputSecondPermutation[8];
    scanf("%d", &i_inputPermutationSize);
    for (int index = 0; index < i_inputPermutationSize; index++)
    {
        scanf("%d", &ia_inputFirstPermutation[index]);
    }
    for (int index = 0; index < i_inputPermutationSize; index++)
    {
        scanf("%d", &ia_inputSecondPermutation[index]);
    }

    long l_firstPermutationNumber = 1;
    long l_secondPermutationNumber = 1;
    for (int index = 0; index < i_inputPermutationSize; index++)
    {
        int counter = ia_inputFirstPermutation[index];
        for (int index2 = index - 1; index2 >= 0; index2--)
        {
            if (ia_inputFirstPermutation[index] > ia_inputFirstPermutation[index2])
            {
                counter--;
            }
        }
        for (int count = 1; count < counter; count++)
        {
            l_firstPermutationNumber += getFactorial(i_inputPermutationSize - (index + 1));
        }
    }
    for (int index = 0; index < i_inputPermutationSize; index++)
    {
        int counter = ia_inputSecondPermutation[index];
        for (int index2 = index - 1; index2 >= 0; index2--)
        {
            if (ia_inputSecondPermutation[index] > ia_inputSecondPermutation[index2])
            {
                counter--;
            }
        }
        for (int count = 1; count < counter; count++)
        {
            l_secondPermutationNumber += getFactorial(i_inputPermutationSize - (index + 1));
        }
    }

    long answer = 0;
    if (l_firstPermutationNumber > l_secondPermutationNumber)
    {
        answer = l_firstPermutationNumber - l_secondPermutationNumber;
    }
    else if (l_firstPermutationNumber < l_secondPermutationNumber)
    {
        answer = l_secondPermutationNumber - l_firstPermutationNumber;
    }

    printf("%ld", answer);

    return 0;
}

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


int main()
{
  int k;
  cin >> k;
  string s;
  cin >> s;
  if (s.size() <= k)
    cout << s << endl;
  else
    cout << s.substr(0, k) << "...\n";
  return 0;
}

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

int main(){
  int N, W;
  cin >> N >> W;
  vector<ll> w(N);
  vector<ll> v(N);
  rep(i, N){
    cin >> w[i] >> v[i];
  }
  vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
  rep(i,N){
    for (int j = 0; j <= W; j++){
      if(j >= w[i]) {
        dp[i + 1][j] = max(dp[i][j - w[i]] + v[i],  dp[i][j]);
      }else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}

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

int main() {
  long long n, m;
  cin >> n >> m;

  if (n>=2 && m>=2) {
      cout << n*m - (n-2)*2 - (m-2)*2 - 4 << endl;
  } else if (n==1 && m==1) {
      cout << 1 << endl;
  } else if (n==1 && m>=2) {
      cout << m-2 << endl;
  } else {
      cout << n-2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    String s = next();

    String aaa = s.toLowerCase();

    if(s.equals(aaa)){
      System.out.println("a");
    }
    else{
      System.out.println("A");
    }

    //System.out.println();

  }

  static int lcm(int a,int b){
    return a*b*gcd(a,b);
  }

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

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

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

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

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

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 35680
#include<cstdio>
#include<iostream>
#include<cstring>
#define in inline
#define re register
using namespace std;
in int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int l,r,ans;
char s[1002];
int main(){
scanf("%s",s);
int tmp=strlen(s)
;
l=0;
r=tmp-1;
while(r>l){
	if(s[l]!=s[r])++ans;
	++l;
	--r;
}
cout<<ans;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> heights(N), dp(N);
	/* Read in first height for the base case */
	cin >> heights[0];
	/* Base case n = 0 is already solved */
    for (int i = 1; i < N; ++i) {
		cin >> heights[i];
		/* Find the best of all K previous stones */
		int best = INT_MAX;
		for (int j = min(K, i); j >= 1; --j)
			best = min(best, dp[i-j] + abs(heights[i] - heights[i-j]));
		/* dp[i] is the best of all the stones */
		dp[i] = best;
    }
    /* Answer is the min total cost of reaching stone N-1 */
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
#coding:utf-8
a, b = map(int, input().split())
count = 0

for i in range(a, b+1):
    num = str(i)
    #print(num[0:2], num[3:5], num)
    #11211のようなパターン
    if num[0] == num[1] and num[0] == num[3] and num[0] == num[4]:
        count += 1
    #23532のようなパターン
    elif num[0] == num[4] and num[1] == num[3]:
        count += 1

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    deque<int> d;
    rep(i,n){
        int t = lower_bound(ALL(d), a[i]) - d.begin();
        if(t == 0) d.push_front(a[i]);
        else d[t-1] = a[i];
    }

    int ans = d.size();
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll x, k, d;

int main() {
    cin >> x >> k >> d;
    ll len = abs(x);
    ll cnt = len/d;
    // cnt回動ければ0付近に持っていける
    if(k <= cnt) {
        ll aaa = len - k*d;
        cout << aaa << endl;
    }else {
        ll ch = len - cnt*d;
        ll ch2 = abs(ch-d);
        // cnt回でchにいる
        ll rest = k-cnt;
        // 残りk-cnt回で偶奇で位置が変わる
        if(rest%2 == 0) cout << ch << endl;
        else cout << ch2 << endl;
    }
}

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


int main()
{
	ll l, r, d;

	scanf("%lld %lld %lld", &l, &r, &d);

	ll res=r/d-(l-1)/d;

	printf("%lld\n", res);



	return 0;
}

Measured memory_bytes: 3720
import sys
import math

dayy = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def days(a, day):
    if a == 0:
        return day
    else:
        return days(a-1, day + dayy[a])


while 1:
    inp = raw_input().split()
    ii = int(inp[0])
    jj = int(inp[1])
    if ii == 0 and jj== 0:
        break
    ans = days(ii-1, 0) + jj
    ans = ans % 7
    if ans == 1:
        print "Thursday"
        continue
    if ans == 2:
        print "Friday"
        continue
    if ans == 3:
        print "Saturday"
        continue
    if ans == 4:
        print "Sunday"
        continue
    if ans == 5:
        print "Monday"
        continue
    if ans == 6:
        print "Tuesday"
        continue
    if ans == 0:
        print "Wednesday"
        continue

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

using namespace std;

int main() {
    int N, Q; cin >> N >> Q;
    int ac_count[N];
    string S; cin >> S;
    int l[Q], r[Q];
    for(int i=0; i<Q; i++) cin >> l[i] >> r[i];
    int result = 0;

    ac_count[0] = 0;
    for (int i=1; i<N; i++) { 
        ac_count[i] = ac_count[i-1] + ( (char)S[i-1] == 'A' and (char)S[i] == 'C' ? 1 : 0 ); 
    }
    for (int i=0; i<Q; i++) {
        result = ac_count[r[i]-1] -ac_count[l[i]-1];
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
 
int main(){
  int i,j,m,l;
  char s[10];
  scanf("%s",s);
  m=0;
  l=0;
  
  for(i=0; s[i]!='\0'; ++i);
  
  for(j=2;j<i-1;j++){
    if(s[j]=='C')
      m=m+1;
    }
  
  
  for(j=1;j<i;j++){
    if(s[j]>=65&&s[j]<=90)
      l=l+1;
  }

  
  if(s[0]!='A')
    printf("WA");
  
  else if(m!=1)
    printf("WA");
  
  else if(l!=1)
    printf("WA");
  
  else printf("AC");
   
}

Measured memory_bytes: 256
l = []

l += list(map(int, input().split()))
l += list(map(int, input().split()))
l += list(map(int, input().split()))

n = int(input())

check = [0]*9

for i in range(n):
    b = int(input())
    if b in l:
        check[l.index(b)] = 1

h1 = check[0]*check[1]*check[2]
h2 = check[3]*check[4]*check[5]
h3 = check[6]*check[7]*check[8]

v1 = check[0]*check[3]*check[6]
v2 = check[1]*check[4]*check[7]
v3 = check[2]*check[5]*check[8]

d1 = check[0]*check[4]*check[8]
d2 = check[2]*check[4]*check[6]

if h1+h2+h3+v1+v2+v3+d1+d2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188
import java.util.Scanner;

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

    while (true){
      int n = input.nextInt();
      if (n == 0) break;
      int a[][] = new int[n + 1][n + 1];

      for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
          a[i][j] = input.nextInt();
          a[i][n] += a[i][j];
          a[n][j] += a[i][j];
        }
        a[n][n] += a[i][n];
      }

      for (int i = 0; i < n + 1; i++){
        for (int j = 0; j < n + 1; j++){
          System.out.print(String.format("%5d", a[i][j]));
        }
        System.out.println();
      }
    }
  }
}

Measured memory_bytes: 32448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll k;
    cin>>k;
    ll ans=0;
    rep(1,i,k+1){
        rep(1,j,k+1){
            rep(1,l,k+1){
                ans+=gcd(i,gcd(j,l));
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>

const int MaxN = 1e6;
using namespace std;
char a[MaxN],b[MaxN];

int main()
{
	int flag=0,n,m,i;
	scanf("%s",a);
	scanf("%s",b);
	n=strlen(a),m=strlen(b);
	if(strcmp(a,b)==0)
		printf("EQUAL\n");
	if(n==m)
	{
		for(i = 0;i < n;i++)
		{
			if(a[i]>b[i])
			{
				flag=1;
				break;
			}
			if(a[i]<b[i])
			{
				flag=2;
				break;
			}
		}
	}
	if(n>m || flag==1)
		printf("GREATER\n");
	if(n<m || flag==2)
		printf("LESS\n");
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >> N ;

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

    bool b[4];
    b[0]=false;
    b[1]=false;
    b[2]=false;
    b[3]=false;

    for(int j=0; j < N; j++){
        if(a[j] == 'P'){
            b[0]=true;
        }else if(a[j] == 'W'){
            b[1]=true;
        }else if(a[j] == 'G'){
            b[2] =true;
        }else if(a[j] == 'Y'){
            b[3] = true;
        }
    }

    int c = 0;
    for(int k=0; k < 4; k++){
        if(b[k] == true){
            c++;
        }
    }

    if(c==3){
        cout << "Three" << endl;
    }else if(c==4){
        cout <<"Four" <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 100000 + 10;
//const int maxn = 100 + 10;
const int N = maxn << 1;
const int maxE = maxn << 3;
const int INF = 0x3f3f3f3f;

int n, a[maxn], b[maxn], pos1[maxn], pos2[maxn], vis[maxn];
int S, T, h[N], ecnt;
struct enode{
	int v, n, w, op;
	enode() {}
	enode(int _v, int _n, int _w, int _op):v(_v), n(_n), w(_w), op(_op) {}
}e[maxE];

inline void addedge(int u, int v, int w) {
//	cout << u << ' ' << v << ' ' << w << endl;
	ecnt ++; e[ecnt] = enode(v,h[u],w,ecnt + 1); h[u] = ecnt;
	ecnt ++; e[ecnt] = enode(u,h[v],0,ecnt - 1); h[v] = ecnt;
}

inline void init(int *a, int *pos) {
	memset(vis,0,sizeof(vis)); int cnt = 0;
	for(int i = 1;i <= n;i ++) {
		if(vis[i]) continue; 
		cnt ++;
		for(int p = i;!vis[p];p = a[p]) {
      pos[p] = cnt;
			vis[p] = 1;
		}
	}
}

int level[N], q[N << 1], cur[N];
inline bool bfs() {
  memset(level,0,sizeof(level));
	for(int i = 1;i <= T;i ++) cur[i] = h[i];
	int head = 1, tail = 0;
	q[++ tail] = S; level[S] = 1;
	while(head <= tail) {
		int u = q[head]; head ++;
		for(int i = h[u];~ i;i = e[i].n) {
			int v = e[i].v;
			if(!level[v] && e[i].w > 0) {
				level[v] = level[u] + 1;
				q[++ tail] = v;
				if(v == T) return 1;
			}
		}
	}
	return 0;
}

int dfs(int u, int c) {
	if(u == T || c == 0) return c;
	int tmp = 0;
	for(int &i = cur[u];~ i;i = e[i].n) {
		int v = e[i].v;
		if(level[v] == level[u] + 1) {
			int x = dfs(v,min(c,e[i].w));
			if(x) {
				tmp += x; c -= x;
				e[i].w -= x; e[e[i].op].w += x;
				if(!c) break;
			}
		}
	}
	if(!tmp) level[u] = -1;
	return tmp;
}

inline int max_flow() {
  int now = 0;
	while(bfs())
		now += dfs(S,INF);
	return now;
}

int main() {
//	freopen("data.in","r",stdin);
  scanf("%d", &n); ecnt = 0;
	memset(h,-1,sizeof(h));
	for(int i = 1;i <= n;i ++) scanf("%d", &a[i]), a[i] ++;
	for(int i = 1;i <= n;i ++) scanf("%d", &b[i]), b[i] ++;
  init(a,pos1);
  init(b,pos2);
	for(int i = 1;i <= n;i ++) pos2[i] += n;
	int Ans = 0; S = n + n + 1, T = S + 1;
	for(int i = 1;i <= n;i ++) if(a[i] != b[i]) Ans ++;
	for(int i = 1;i <= n;i ++) {
//    cout << "work " << i << endl;
		if(a[i] == b[i]) {
			if(a[i] == i) continue;
			else {
				Ans ++;
				addedge(pos1[i],pos2[i],1);
				addedge(pos2[i],pos1[i],1);
			}
		}
		else {
			if(a[i] == i) addedge(S,pos2[i],1);
			else if(b[i] == i) addedge(pos1[i],T,1);
			else addedge(pos1[i],pos2[i],1);
		}
	}
	int now = max_flow();
	Ans -= now;
	printf("%d\n", Ans);
	return 0;
}


Measured memory_bytes: 13568
from bisect import bisect

s,t = input(),input()
n,x,nx,r = len(s),s+s,{},0

for i,c in enumerate(x):
	if nx.get(c) is None:
		nx[c] = []
	nx[c].append(i+1)

for c in t:
	l = nx.get(c)
	if l is None:
		print(-1)
		exit()
	r += l[bisect(l,r%n)]-r%n
print(r)

Measured memory_bytes: 87604
#include<iostream>


int main(){
	int na;
	std::cin>>na;
	for(int i = 1; ++i <= na;){
		if(i % 3 == 0 || i % 10 == 3 || i / 10 % 10 == 3 || i / 100 % 10 == 3 ||
			i / 1000 % 10 == 3 || i / 10000 % 10 == 3 ){
			std::cout<<" "<<i;
		}
	}
	std::cout<<std::endl;
	return 0;
}

Measured memory_bytes: 1164
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define show(ans) cout << ans << endl
const long MOD = 1000000007;




int main() {
	string S;
	cin >> S;
	if (S > "2019/04/30") show("TBD");
	else show("Heisei");
	return 0;

}


Measured memory_bytes: 256
#include <bitset>
#include <iostream>
#include <string>

using namespace std;

struct node {
  node *l;
  node *r;
  node *p;
};

node *parse(string str) {

  node *base = new node({});
  node *p = base;

  bool flag = true;
  for (auto &c : str) {
    switch (c) {
    case '(': {
      node *p_new = new node({nullptr, nullptr, p});
      if (flag)
        p = p->l = p_new;
      else
        p = p->r = p_new;
      flag = true;
      break;
    }
    case ',': {
      flag = false;
      break;
    }
    case ')': {
      p = p->p;
      break;
    }
    };
  }
  return base->l;
}

void print_tree_intersection(node *tree1, node *tree2, bool endl_flag=true) {
  if ( (tree1 == nullptr) || (tree2 == nullptr) )
    return;

  cout << '(';
  print_tree_intersection(tree1->l, tree2->l, false);
  cout << ',';
  print_tree_intersection(tree1->r, tree2->r, false);
  cout << ')';

  if (endl_flag)
    cout << endl;
}

void print_tree_union(node *tree1, node *tree2, bool endl_flag=true) {
  if ( (tree1 != nullptr) && (tree2 != nullptr) ) {
    cout << '(';
    print_tree_union(tree1->l, tree2->l, false);
    cout << ',';
    print_tree_union(tree1->r, tree2->r, false);
    cout << ')';
  } else if ( (tree1 != nullptr) || (tree2 != nullptr) ) {
    node *p = (tree1) ? tree1 : tree2;
    cout << '(';
    print_tree_union(p->l, nullptr, false);
    cout << ',';
    print_tree_union(p->r, nullptr, false);
    cout << ')';
  }

  if (endl_flag)
    cout << endl;
}

int main() {

  while (true) {
    char iu;
    string str1, str2;
    cin >> iu >> str1 >> str2;

    if (cin.fail())
      break;

    node *tree1 = parse(str1);
    node *tree2 = parse(str2);

    if (iu == 'i')
      print_tree_intersection(tree1, tree2);
    else
      print_tree_union(tree1, tree2);
  }
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

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

    cout << (a - 1) * (b - 1) << endl;
    return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define mod 1000000007

int main()
{

    ll n,m;
    cin >> n >> m;
    vector<pll> st, cp;
    for(ll i=0; i < n; i++)
    {

        ll x,y;
        cin >> x >> y;
        st.pb(mp(x,y));
    }
    for(ll i=0; i < m;i++)
    {

        ll x,y;
        cin >> x >> y;
        cp.pb(mp(x,y));
    }
    for(ll i=0; i  <n; i++)
    {

        ll id=-1, dis=inf;
        for(ll j=0; j < m; j++)
        {

            ll x=abs(st[i].ff-cp[j].ff)+abs(st[i].ss-cp[j].ss);
            if(x < dis)
            {

                dis=x;
                id=j+1;
            }
        }
        cout << id << endl;
    }
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())

C = []
A = []

for _ in range(N):
    q = list(map(int, input().split()))

    C.append(q[0])
    A.append(q[1:])

#bit全探索

ans = 1300000

for bit in range(1 << N):
    acquire = [0] * M
    cost = 0
    for i in range(N):
        if (bit >> i) % 2 == 1:
            cost += C[i]
            acquire = [a + b for a, b in zip(acquire, A[i])]

    if min(acquire) >= X:
        ans = min(ans, cost)

if ans == 1300000:
    ans = -1

print(ans)

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    vector<int> atcoder {111, 222, 333, 444, 555, 666, 777, 888, 999};
    int n; cin >> n;
    cout << *lower_bound(atcoder.begin(), atcoder.end(), n) << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        int max = (n - 1) * (n - 2) / 2;
        if (k > max) {
            System.out.println("-1");
            System.exit(0);
        }

        if (k == max) {
            System.out.println(n - 1);
            for (int i = 2; i <= n; i++) {
                System.out.println("1 " + i);
            }
        } else {
            int x = max - k;
            System.out.println(n - 1 + x);
            for (int i = 2; i <= n; i++) {
                System.out.println("1 " + i);
            }

            for (int i = 2; i < n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    if (x <= 0) break;
                    System.out.println(i + " " + j);
                    x--;
                }
            }

        }
    }
    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 24660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll X, Y; cin >> X >> Y;
    REP(turu, X+1) {
        REP(kame, X+1) {
            if (turu*2 + kame*4 == Y && turu+kame == X) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
using namespace std;
int main(){
	while(1){
		int m,n;
		char cha[100000],con[100000],a[100000];
		cin>>m;
		if(m==0)break;
		for(int i=0;i<m;i++){
			cin>>cha[i]>>con[i];
		}
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>a[i];
			for(int j=0;j<m;j++){
				if(a[i]==cha[j]){
					a[i]=con[j];
					break;
				}
			}
		}
		for(int i=0;i<n;i++){
			cout<<a[i];
		}
		cout<<"\n";
	}
	return 0;
}

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

int next_combination(int sub){
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main() {
    int n;
    int k;
    cin >> n >> k;
    
    int bit = (1<<k)-1;
    for(;bit < (1<<n); bit = next_combination(bit)){
        vector<int> S;
        for(int i=0; i<n; i++){
            if(bit & (1<<i)){
                S.push_back(i);
            }
        }
        
        cout << bit <<":";
        for(int i=0; i<(int)S.size(); i++){
            cout <<" "<< S[i];
        }
        cout << endl;
    }
}



Measured memory_bytes: 3168
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>

#define M 1000000000

using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n-1];
    for(int i(0); i<n;i++) cin >> a[i];
    for(int i(0); i<n;i++) cin >> b[i];
    for(int i(0); i<n-1;i++) cin >> c[i];
    
    int ans(0);
    for(int i(0);i<n;i++){
        ans += b[a[i]-1];
        if(a[i+1]-a[i] == 1 && i<n-1) ans += c[a[i]-1];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

int main(){
  string S;
  cin >> S;
  S = S + "R";

  vector<int> RL;
  map<int, int> num;
  int cnt = 0;

  for(int i = 0; i < S.size() - 1; i++){
    cnt++;
    if(S[i] != S[i+1]){
      RL.push_back(cnt);
      cnt = 0;
    }
  }

  cnt = 0;

  for(int i = 0; i < RL.size(); i = i+2){
    num[RL[i]+cnt] += RL[i]/2 + RL[i+1]/2 + (RL[i+1]%2);
    num[RL[i]+cnt-1] += RL[i]/2 + (RL[i]%2) + RL[i+1]/2;
    cnt += RL[i] + RL[i+1];
  }

  for(int i = 0; i < S.size() - 1; i++) cout << num[i] << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,ans,i,j,k;
	cin>>n;
	map<int,int>mp;
	for(i=1;i*i<=n;i++){
		for(j=1;j*j<=n;j++){
			for(k=1;k*k<=n;k++){
				ans=i*i+j*j+k*k+i*j+i*k+j*k;
				mp[ans]++;
			}
		}
	}
	for(i=1;i<=n;i++)
	cout<<mp[i]<<endl;
}


Measured memory_bytes: 5204
//use proconio::input;
use std::cmp::min;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        h: [i32; n],
    }
    let mut dp = vec![0; n];
    let m = 2;
    dp[1] = (h[1] - h[0]).abs();
    for i in m..n {
        let mut dpi = dp[i - 1] + (h[i] - h[i - 1]).abs();
        for j in 2..(m + 1) {
            dpi = min(dpi, dp[i - j] + (h[i] - h[i - j]).abs());
        }
        dp[i] = dpi;
    }

    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()
#define tc int t;scanf("%d",&t);while (t--0)
typedef long long ll;
const ll MOD=1e9+7;
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
ll invmod(ll x) {return power(x,MOD-2);}
int gcd(int a,int b)
{
	if(a==0)
		return b;
	else
		return gcd(b%a,a);
}
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int max1=0;
	max1=max(max1,10*a+b+c);
	max1=max(max1,a+b+10*c);
	max1=max(max1,a+10*b+c);
	cout<<max1<<endl;





	

	
}

Measured memory_bytes: 256
alp='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n=int(input())
s=input()
num=[]
for i in range(len(s)):
    num.append(alp.index(s[i]))
import numpy as np
num=np.array(num)
num=(num+n)%26
ans=''
for i in num:
    ans+=alp[i]
    
print(ans)

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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define fast_work {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

const ll INF = 1e18 + 7, NMAX = 1e6 + 5, MOD = 1000000007, N = 1e9 + 5, LOG = 25;
const ld EPS = 1e-8, pi = 3.14159265358979323846;

ll x, k, d;
ll f(ll a) {
    return abs(x - k * d + 2 * a * d);
}

signed main() {
    fast_work
    cin >> x >> k >> d;

    ll a = max(k / 2.0 - x / (2.0 * d), 0.0);
    if(a > k) a = k;
    ll a1 = a > 0? a - 1 : 0;
    ll a2 = min(a + 1, k);
    cout << min({f(a1), f(a2), f(a)});
}





Measured memory_bytes: 3596
S = input()
S_list = list(S)
S_len = len(S)
compare = ''
abs_list = []
#print(S_list)
i = 0

while True:
    for m in range(i, i+3):
        compare += S_list[m]
    #    print(m)
    #   print(S_list[m])
    #    print(compare)
        if m == S_len:
            break
    i+=1
    int_compare = int(compare)
    abs_list.append(abs(int_compare-753))
    compare = ''
    #print(abs_list)
    if i+3 > S_len:
        break

ans = min(abs_list)
print(ans)

Measured memory_bytes: 3064
L,R = map(int,input().split())
if R-L >= 2019:
    print(0)
else:
    mR = R%2019
    mL = L%2019
    if mL > mR:
        print(0)
    else:
        mini = 2019
        for i in range(mL, mR):
            for j in range(i+1, mR+1):
                mini = min(mini, (i*j)%2019)
        print(mini)

Measured memory_bytes: 65400