akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
using namespace std;

const int sx[] = {0, 3, 6, 0, 3, 6, 0, 3, 6};
const int sy[] = {0, 0, 0, 3, 3, 3, 6, 6, 6};

bool valid[9][9];
int puzzle[9][9];

int main()
{
  int n;
  while (~scanf("%d", &n)) {
    for (int dataset = 0; dataset < n; ++dataset) {
      if (dataset != 0)
	puts("");

      for (int i = 0; i < 9; ++i) {
	for (int j = 0; j < 9; ++j) {
	  scanf("%d", &puzzle[i][j]);
	  valid[i][j] = true;
	}
      }

      // horizonal/vertical
      for (int i = 0; i < 9; ++i) {
	vector<int> h_cnt(10, 0), v_cnt(10, 0);
	for (int j = 0; j < 9; ++j) {
	  ++h_cnt[puzzle[i][j]];
	  ++v_cnt[puzzle[j][i]];
	}
	for (int j = 0; j < 9; ++j) {
	  if (h_cnt[puzzle[i][j]] != 1)
	    valid[i][j] = false;
	  if (v_cnt[puzzle[j][i]] != 1)
	    valid[j][i] = false;
	}
      }

      // block
      for (int b = 0; b < 9; ++b) {
	vector<int> cnt(10, 0);
	for (int i = sy[b]; i < sy[b]+3; ++i) {
	  for (int j = sx[b]; j < sx[b]+3; ++j) {
	    ++cnt[puzzle[i][j]];
	  }
	}
	for (int i = sy[b]; i < sy[b]+3; ++i) {
	  for (int j = sx[b]; j < sx[b]+3; ++j) {
	    if (cnt[puzzle[i][j]] != 1)
	      valid[i][j] = false;
	  }
	}
      }

      for (int i = 0; i < 9; ++i) {
	for (int j = 0; j < 9; ++j) {
	  if (valid[i][j])
	    printf(" %d", puzzle[i][j]);
	  else
	    printf("*%d", puzzle[i][j]);
	}
	puts("");
      }
    }
  }
  return 0;
}

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

int main(void){
    ll n, k;
    cin >> n >> k;

    ll a[n];
    ll p_1;
    rep(i, n){
        cin >> a[i];
        if(a[i] == 1)
            p_1 = i;
    }

    ll count = ceil(double((n - 1) / (k - 1.0)));
    cout << count << endl;
    return 0;
}


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

int main() {
    int n;
    while (cin >> n, n) {

        // vector< pair<int, char> > a(30, {0, 'a'});
        vector< char > inp(n);

        rep(i, n) {
            cin >> inp[i];
            //a[inp[i] - 'A'] = { a[inp[i] - 'A'].first + 1, inp[i] };
        }

        // if (n == 1) {
        //     cout << inp[0] << ' ' << 1 << endl;
        //     continue;
        // }
        //
        // sort(a.begin(), a.end(), greater< pair<int, char> >());
        // if (a[0].first == a[1].first) {
        //     cout << "TIE" << endl;
        //     continue;
        // }
        //
        // char win = a[0].second;

        bool flag=false;
        map<char, int> mp;
        rep(i, n) {

            if (mp.count(inp[i])) mp[inp[i]]++;
            else mp[inp[i]] = 1;

            int ma=0;
            char ch;
            for (auto t : mp) {
                if (ma < t.second) {
                    ma = t.second;
                    ch = t.first;
                }
            }
            int ma2=0;
            for (auto t : mp) if (ch != t.first) ma2 = max(ma2, t.second);

            if (ma > ma2 and ma - ma2 > n-(i+1)) {
                cout << ch << ' ' << i + 1 << endl;
                flag = true;
                break;
            }
        }

        if (!flag) cout << "TIE" << endl;



    }
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int l[n];
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l,l+n);
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=(ll)(lower_bound(l+(j+1),l+n,l[i]+l[j])-(l+j+1));
        }
    }
    cout<<ans<<endl;
}

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll i = N % 10;
    switch(i){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        case 3:
            cout << "bon" << endl;
            break;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int N,L;
    cin >> N >> L;
    int sum = 0;
    int e = 1000;
    for(int i=0;i<N;i++){
        int a = L + i;
        sum += a;
        if(abs(e) > abs(a)){
            e = a;
        }
    }
    int ans = sum - e;
    cout << ans << endl;
}


Measured memory_bytes: 3176
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())
b = list(map(abs,a))

ind = b.index(min(b))

c = deepcopy(a)
# print(c)
i = 0
while i<(ind):
    s = c[i]
    t = c[i+1]
    if s>=0 and t>=0:
        i += 2
    elif s>=0 and t<=0:
        i += 1
    elif s<=0 and t>=0:
        c[i] = -1*s
        c[i+1] = -1*t
        i += 1
    elif s<=0 and t<=0:
        c[i] = -1*s
        c[i+1] = -1*t
        i += 2
# print(c)
d = c[::-1]
# print(d)
i = 0
while i<(n-ind-1):
    s = d[i]
    t = d[i+1]
    if s>=0 and t>=0:
        i += 2
    elif s>=0 and t<=0:
        i += 1
    elif s<=0 and t>=0:
        d[i] = -1*s
        d[i+1] = -1*t
        i += 1
    elif s<=0 and t<=0:
        d[i] = -1*s
        d[i+1] = -1*t
        i += 2
# print(d)

ans = sum(d)
print(ans)

Measured memory_bytes: 118616
h,w,k = map(int,input().split())
st = []
for i in range(h):
  s = str(input())
  st.append(s)
res = [[0 for _ in range(w)] for _ in range(h)]
i = 0
j = 0
p = 0
q = 0
c = 1
while j < h:
  flag = False
  while q < w:
    if st[j][q] == "#":
      for y in range(i,j+1):
        for x in range(p,q+1):
          res[y][x] = c
      flag = True
      c += 1
      p = q+1
    q += 1
  if flag:
    i = j+1
  j += 1
  p = 0
  q = 0
for m in range(h):
  for n in range(w):
    if res[m][n] == 0:
      if m < i:
        res[m][n] = res[m][n-1]
      else:
        res[m][n] = res[m-1][n]
for m in range(h):
  for n in range(w-1):
    print(res[m][n],end=" ")
  print(res[m][w-1])

Measured memory_bytes: 51800
function main(input) {
  const formatted_input = input.split('\n')[0];
  const S = formatted_input;

  var result = 0;
  var tmp = 0;
  for(var i=0;i<S.split('').length;i++){
    var b=S.split('')[i];

    if(b=='A' || b=='T' || b=='G' || b=='C'){
      tmp++;
    }else{
      result = Math.max(result, tmp);
      tmp=0;
    }
  }
  result = Math.max(result, tmp);

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

int main(){

    char a[3];
    cin>>a;
    //cin>>b;
    //cin>>c;
    int counter=0;
    
    if(a[0]=='7'){
        counter+=1;
    }
    if(a[1]=='7'){
        counter+=1;
    }
    if(a[2]=='7'){
        counter+=1;
    }
    
    if(counter>0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

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

using namespace std;

int main()
{
    string s; cin >> s;
    cout << (count(s.begin(), s.end(), 'a') && count(s.begin(), s.end(), 'b') && count(s.begin(), s.end(), 'c') ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 888
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		// 文字列の入力
		// 出力
      	if(d==1){
			System.out.println(1);    
        }else{
			System.out.println(0);
        }
	}
}

Measured memory_bytes: 23764
/** @Date    : 2017-07-09 11:36:17
  * @FileName: C 构造.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;


int a[600][600];
int main()
{	
	int n, m;
	int x, y;
	while(cin >> n >> m >> x >> y)
	{
		if(n % x == 0 && m % y == 0)
		{
			printf("No\n");
			continue;
		}
		printf("Yes\n");
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= m; j++)
			{
				if(j % y == 0 && i % x == 0)
					a[i][j] = -(x * y - 1) * 2000 - 1;
				else a[i][j] = 2000;
			}
		}

		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
				printf("%d%s", a[i][j], j==m?"\n":" ");
	}

    return 0;
}

Measured memory_bytes: 2688
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		String op = s.next();
		int b = s.nextInt();
		int answer = 0;
		

		if(op.equals("+")) {
			answer = a + b;
		}else if(op.equals("-")) {
			answer = a - b;
		}

		System.out.println(answer);

	}

}

Measured memory_bytes: 20692
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

int abs(int x){
    if(x<0){
	x*=-1;
    }
    return x;
}

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

    int w,h,n;
    cin>>w>>h>>n;
    bool white[105][105]={false};

    int x,y,a;
    rep(i,n){
	cin>>x>>y>>a;


	if(a==1){
	    
	    for(int i=1;i<=x;i++){
		for(int j=1;j<=h;j++){
		    white[i][j]=true;
		}
	    }
	    
	}

	if(a==2){
	    
	    for(int i=x+1;i<=w;i++){
		for(int j=1;j<=h;j++){
		    white[i][j]=true;
		}
	    }
	}

	if(a==3){
	    
	    for(int i=1;i<=w;i++){
		for(int j=1;j<=y;j++){
		    white[i][j]=true;
		}
	    }
	    
	}

	if(a==4){
	    for(int i=1;i<=w;i++){
		for(int j=y+1;j<=h;j++){
		    white[i][j]=true;
		}
	    }
	}
	
    }
    
    int sum=0;
    reps(i,w){
	reps(j,h){
	    if(!white[i][j]){
		sum++;
	    }
	}
    }
    
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int c=0;
  for(int i=0; i<s.size(); i++){
    if(s[i]!=t[i]) c++;
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
int A,X;
int main(void){
    scanf("%d%d",&X,&A);
    puts(X<A?"0":"10");
    return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int r = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') r++;
        else b++;
    }
    cout << (r > b ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#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, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main()
{
    int N;
    cin >> N;
    while (N--)
    {
        int t;
        cin >> t;
        a[t]++;
        a[t + 1]++;
        a[t + 2]++;
    }
    cout << *max_element(a + 2, a + 100000) << endl;
    return 0;
}

Measured memory_bytes: 3792
W,H = map(int,input().split())
while W != 0:
    for i in range(W):
        for j in range(H):
            if i == 0 or i == W-1 or j == 0 or j==H-1:
                print('#',end='')
            else:
                print('.',end='')
            
        print()
    print()
    W,H = map(int,input().split())


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int ramen = 700;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == 'o') {
      ramen += 100;
    }
    else {
      ramen += 0;
    }
  }
  cout << ramen << endl;
}

  
    

Measured memory_bytes: 3608
/*
 * Ankit Raj, NIT Agartala
 */
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
#define MAX_RANGE 10000007
#define BOOST ios_base::sync_with_stdio(0) 
#define NITRO cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define F first
#define S second
int main()
{
	BOOST;
	NITRO;
	clock_t t1,t2;
	t1 = clock();
	/*
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	*/ 
	//Main Code
	int n;
	cin>>n;
	int arr[n];
	int dp[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1]<<"\n";
	

	t2 = clock();
	float diff = (float)t2 - (float)t1;
	float execution_time = diff/CLOCKS_PER_SEC;
	//cout<<"\n"<<execution_time;
	//system("pause");
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    vector<vector<int>> cnt(60, vector<int>(2, 0));
    REP (i, N) {
        cin >> A[i];
        REP (j, 60) cnt[j][A[i] >> j & 1]++;
    }
    int ans = 0, tmp = 0;
    REP (i, N) tmp += (K ^ A[i]);
    ans = tmp;
    tmp = 0;
    for (int i = 59; i >= 0; --i) {
        if (K >> i & 1) {
            int add = 0, add2 = 0;
            for (int j = i - 1; j >= 0; --j) {
                if (K >> j & 1) add += (1LL << j) * max(cnt[j][0], cnt[j][1]);
                else add += (1LL << j) * cnt[j][1];
                add2 += (1LL << j) * max(cnt[j][0], cnt[j][1]);
            }
            ans = max({ans, tmp + (1LL << i) * cnt[i][0] + add, tmp + (1LL << i) * cnt[i][1] + add2});
        }
        tmp += (1LL << i) * cnt[i][(K >> i & 1) ^ 1];
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  k--;
  if (s[k] == 'A') s[k] = 'a';
  if (s[k] == 'B') s[k] = 'b';
  if (s[k] == 'C') s[k] = 'c';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < int(n.length()); i++) {
    cnt += n[i] - 48;
  }
  if (cnt % 9 == 0 || cnt == 0) cout << "Yes";
  else cout << "No";
}

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

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public int d { get; set; }
    public string via { get; set; }
    public int count { get; set; }
}

public class hello
{
    public static Dictionary<char, int> d0;
    public static Dictionary<int, string> d1;
    public static char[,] map;
    public static int h, w;

    public static void Main()
    {
        d0 = new Dictionary<char, int>() { { 'R', 0 }, { 'D', 1 }, { 'L', 2 }, { 'U', 3 } };
        d1 = new Dictionary<int, string>() { { 0, "R" }, { 1, "D" }, { 2, "L" }, { 3, "U" } };
        string[] line = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line[0]);
        w = int.Parse(line[1]);
        map = new char[h, w];
        var sx = 0; var sy = 0; var sd = -1;
        var Lc = 0;
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
            {
                if (s[j] != 'o' && s[j] != '.')
                {
                    sx = i;
                    sy = j;
                    sd = d0[s[j]];
                    map[i, j] = '.';
                }
                else
                {
                    map[i, j] = s[j];
                    if (s[j] == 'o') Lc++;
                }
            }
        }
        goDfs(sx, sy, sd, Lc, "");
    }
    static void goDfs(int x, int y, int d, int Lc, string via)
    {
        if (Lc == 0) { Console.WriteLine(via); return; }
        var tw = getLeaf(x, y, d);
        if (tw != -1)
        {
            map[x, y] = '.';
            if (d == 0 | d == 2) goDfs(x, tw, d, Lc - 1, via + d1[d]);
            else goDfs(tw, y, d, Lc - 1, via + d1[d]);
            map[x, y] = 'o';
        }
        var td2 = d + 1;
        if (td2 > 3) td2 -= 4;
        tw = getLeaf(x, y, td2);
        if (tw != -1)
        {
            map[x, y] = '.';
            if (td2 == 0 | td2 == 2) goDfs(x, tw, td2, Lc - 1, via + d1[td2]);
            else goDfs(tw, y, td2, Lc - 1, via + d1[td2]);
            map[x, y] = 'o';
        }
        var td3 = d - 1;
        if (td3 < 0) td3 += 4;
        tw = getLeaf(x, y, td3);
        if (tw != -1)
        {
            map[x, y] = '.';
            if (td3 == 0 | td3 == 2) goDfs(x, tw, td3, Lc - 1, via + d1[td3]);
            else goDfs(tw, y, td3, Lc - 1, via + d1[td3]);
            map[x, y] = 'o';
        }
    }
    static int getLeaf(int x, int y, int d)
    {
        var nx = x; var ny = y;
        while (true)
        {
            if (d == 0) ny++;
            else if (d == 1) nx++;
            else if (d == 2) ny--;
            else nx--;
            if (nx < 0 | nx >= h | ny < 0 | ny >= w) return -1;
            if (map[nx, ny] == 'o')
            {
                if (d == 0 | d == 2) return ny;
                else return nx;
            }
        }
    }
}



Measured memory_bytes: 18152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		int count = 0;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String word = br.readLine();
		while(true) {
			String sentence = br.readLine();
			if (sentence.equals("END_OF_TEXT")){
				break;
			}
			String[] sentence_word = sentence.split(" ");
			for (int i = 0;i < sentence_word.length;i++){
				if (sentence_word[i].equalsIgnoreCase(word)){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24176
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=3005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T>inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[10];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,a[N],dp[N];
bool vis[N];
vi g[N];

bool dfs(int x){
	vis[x]=1;
	for(int i=0;i<g[x].size();i++){
		int y=g[x][i];
		if(a[y]>=a[x]||vis[y]) continue;
		if(!dfs(y)) return 1;
	}
	return 0;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++){
		int x,y;scanf("%d%d",&x,&y);
		g[x].pb(y);g[y].pb(x);
	}
	for(int i=1;i<=n;i++){
		clr(vis,0);
		if(dfs(i)) printf("%d ",i);
	}
	return 0;
}	

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
   
  string s;
  cin>>s;

  for(auto ele : s)
    if(ele == '7')
      return cout<<"Yes",0;

  cout<<"No";   
   return 0;
}

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

#define INF 1234567890
#define ll long long

struct Node {
	int d, k, t; // delta, K, type = 0이면 왼쪽 1이면 오른쪽
	bool operator<(Node &n)
	{
		return d > n.d;
	}
};

int T, N;
ll res;
vector<Node> v;
int p[2][200201];

int Find(int t, int n)
{
	if (n == p[t][n]) return n;
	return p[t][n] = Find(t, p[t][n]);
}

void Union(int t, int a, int b)
{
	a = Find(t, a); b = Find(t, b);
	if (a == b) return;
	p[t][a] = b;
}

int main()
{
	scanf("%d", &T);
	while(T--)
	{
		// clear
		res = 0;
		v.clear();

		scanf("%d", &N);
		for(int i=0; i<=N+1; i++)
			p[0][i] = p[1][i] = i;

		for(int i=1; i<=N; i++)
		{
			int k, l, r;
			scanf("%d %d %d", &k, &l, &r);
			res += min(l, r);
			if (l >= r) v.push_back({l-r, k, 0});
			else v.push_back({r-l, k, 1});
		}
		sort(v.begin(), v.end());
		for(auto it : v)
		{
			if (it.t == 0)
			{
				int n = Find(0, it.k);
				if (n == 0) continue;
				Union(0, n, n-1);
				res += it.d;
			}
			else
			{
				int n = Find(1, it.k+1);
				if (n == N+1) continue;
				Union(1, n, n+1);
				res += it.d;
			}
		}
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 7972
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int R, S, P;

ll cal(string strg, char max_rsp, int repeat) {
    ll value = 0;
    for (int i = 0; i < repeat; i++) {
        switch (max_rsp) {
            case 'r':
                if (strg[i] == 's') {
                    value += R;
                    continue;
                }
                break;
            case 's':
                if (strg[i] == 'p') {
                    value += S;
                    continue;
                }
                break;
            case 'p':
                if (strg[i] == 'r') {
                    value += P;
                    continue;
                }
                break;
        }
        switch (strg[i]) {
            case 'r':
                value += P;
                break;
            case 's':
                value += R;
                break;
            case 'p':
                value += S;
                break;
        }
    }
    for (int i = repeat; i < strg.length(); i++) {
        switch (max_rsp) {
            case 'r':
                if (strg[i] == 's' && strg[i-repeat]!='s') {
                    value += R;
                    continue;
                } else if (strg[i] == 's') {
                    strg[i] = '0';
                    continue;
                }
                break;
            case 's':
                if (strg[i] == 'p' && strg[i - repeat] != 'p') {
                    value += S;
                    continue;
                } else if (strg[i] == 'p') {
                    strg[i] = '0';
                    continue;
                }
                break;
            case 'p':
                if (strg[i] == 'r' && strg[i - repeat] != 'r') {
                    value += P;
                    continue;
                } else if (strg[i] == 'r') {
                    strg[i] = '0';
                    continue;
                }
                break;
        }
        switch (strg[i]) {
            case 'r':
                if (strg[i - repeat] != 'r') {
                    value += P;
                } else {
                    strg[i] = '0';
                }
                break;
            case 's':
                if (strg[i - repeat] != 's') {
                    value += R;
                } else {
                    strg[i] = '0';
                }
                break;
            case 'p':
                if (strg[i - repeat] != 'p') {
                    value += S;
                } else {
                    strg[i] = '0';
                }
                break;
        }
    }
    return value;
}

int main() {
    int N, K;
    char ch;
    string T;
    cin >> N >> K >> R >> S >> P;
    cin.get();
    cin >> T;

    if (R > S && R > P) {
        ch = 'r';
    } else if (S > R && S > P) {
        ch = 's';
    } else if (P > S && P > R) {
        ch = 'p';
    }

    cout << cal(T, ch, K);

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <memory.h>
using namespace std;


int toMin(int h) {
  int ret = h / 100 * 60 + h % 100;
  return ret;
}

int main() {
  while(1) {
    int n, p, q;
    scanf("%d %d %d",&n,&p,&q);
    if(n == 0 && p == 0 && q == 0) break;
    p = toMin(p);
    q = toMin(q)-1;
    int count[q+1];
    for(int i = 0; i < p; i++) {
      count[i] = n;
    }
    for(int i = p; i <= q; i++) {
      count[i] = 0;
    }
    for(int i = 0; i < n; i++) {
      int m;
      scanf("%d",&m);
      for(int j = 0; j < m; j++) {
        int st,et;
        scanf("%d %d",&st,&et);
        st = toMin(st);
        et = toMin(et)-1;
        for(int k = st; k <= et; k++) {
          count[k]++;
        }
      }
    }
    int MAX = 0;
    int cou = 0;
    for(int i = p; i <= q; i++) {
      if(count[i] < n) {
        cou++;
        MAX = max(MAX,cou);
      }
      else {
        cou = 0;
      }
    }
    printf("%d\n",MAX);


  }
}

Measured memory_bytes: 1192
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
b = [int(input()) for _ in range(N)]

for i in range(N):
  if b[i] in A1:
    if len(list(set(A1))) == 1:
      A1 = [0] * 3
    else:
      A1[A1.index(b[i])] = 0
  elif b[i] in A2:
    if len(list(set(A2))) == 1:
      A2 = [0] * 3
    else:
      A2[A2.index(b[i])] = 0
  elif b[i] in A3:
    if len(list(set(A3))) == 1:
      A3 = [0] * 3
    else:
      A3[A3.index(b[i])] = 0


if A1[0] == 0 and A1[0] == A2[0] == A3[0]:
  ans = "Yes"
elif A1[1] == 0 and A1[1] == A2[1] == A3[1]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[2] == A3[2]:
  ans = "Yes"
elif A1[0] == 0 and A1[0] == A2[1] == A3[2]:
  ans = "Yes"
elif A1[2] == 0 and A1[2] == A2[1] == A3[0]:
  ans = "Yes"
elif A1 == [0] * 3 or A2 == [0] * 3 or A3 == [0] * 3:
  ans = "Yes"
else:
  ans = "No"

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
 
    void solve (){
        ll x;
        cin>>x;
        int n=5;
        vector<ll>a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        ll mini=*min_element(a.begin(),a.end());
        ll t1=x/mini;
        if(x%mini)
            t1++;
        t1+=4LL;
        cout<<t1;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

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

int main() {
  int N;
  long long T;
  cin >> N >> T;
  long long sum = T;
  vector<long long> t(N);
  for(int i = 0 ; i < N; i++) {
    cin >> t.at(i);
  }
  vector<long long> s(N-1);
  for(int i = 0 ; i < N-1; i++) {
    s.at(i) = t.at(i+1) - t.at(i);
  }
  for(int i = 0 ; i < N-1; i++) {
    sum += min(T,s.at(i));
  }
  cout << sum;
}



Measured memory_bytes: 3328
N=int(input())
A=[int(i) for i in input().split()]
D=max(A)
L=[0]*(D+1)
for i in range(N):
  L[A[i]]+=1
if D==1:
  if N>2:
    print("Impossible")
    exit()
elif D%2==0:
  for i in range(D+1):
    if i<D//2 and L[i]>0:
      print("Impossible")
      exit()
    elif i==D//2 and L[i]!=1:
      print("Impossible")
      exit()
    elif i>D//2 and L[i]<2:
      print("Impossible")
      exit()
elif D%2==1:
  for i in range(D+1):
    if i<D//2+1 and L[i]>0:
      print("Impossible")
      exit()
    elif i==D//2+1 and L[i]!=2:
      print("Impossible")
      exit()
    elif i>D//2+1 and L[i]<2:
      print("Impossible")
      exit()
print("Possible")
    
    
    
  
  

Measured memory_bytes: 38384
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        r: usize,
        g: usize,
        b: usize,
    };
    println!(
        "{}",
        ["NO", "YES"][((r * 100 + g * 10 + b) % 4 == 0) as usize]
    );
}


Measured memory_bytes: 2124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int H,W; cin>>H>>W;
  vector<string> C(H);
  for(auto& c : C) {
    cin >> c;
  }

  for(int i = 1; i <= 2 * H; i++) {
    int org_idx = (i + 1) / 2 - 1;
    for(int j = 0; j < W; j++) {
      cout << C[org_idx][j];
    }
    cout << endl;
  }
}


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

int main(void) {
    int a, b, c; cin >> a >> b >> c;
    set<int> wt;
    int t = 0;
    while (1) {
        auto st = wt.insert(t%60);
        if (!st.second) {
            cout << -1 << endl;
            break;
        }

        if (t%60 <= c && c <= t%60+a) {
            cout << t + c-t%60 << endl;
            break;
        }

        t += a+b;
    }

    return 0;
}

Measured memory_bytes: 3120
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    }
    println!("{}",if a%2==0 {a }else{a*2})
}

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

//部分集合の問題
//二進数として見てやると奇麗に溶ける。

const int INF=1000000001;
int A[100][100];

signed main(){
  int N,M,X;
  cin>>N>>M>>X;
  vector<int> C(N);
  rep(i,N){
    cin>>C[i];
    rep(j,M)cin>>A[i][j];
  }
  
  int ans=INF;
  //”<<”シフト演算子
  //二進数で見たときに１をNシフトさせるとすると、N左に移動させる。
  //0001 <<3 1000 つまり1<<NはNの二乗
  rep(S,1<<N){
    int cost=0;
    vector<int> D(M);
    rep(i,N){
      //>>iして&1をすると、ibitが1かどうか判断できる。
      //i=1; 010 >>1 01,;1&1=true;実行される。
      //&は双方1のときのみ1を返してくれる。
      if(S>>i&1){
        cost+=C[i];
        rep(j,M)D[j]+=A[i][j];
      }
    }
    bool check=true;
    rep(j,M)if(D[j]<X)check=false;
    if(check)ans=min(ans,cost);
  }
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3608
a_coins = int(input())
b_coins = int(input())
c_coins = int(input())
num = int(input())

count = 0

for a in range(0, a_coins + 1):
    for b in range(0, b_coins + 1):
        for c in range(0, c_coins + 1):
            total =  a * 500 + b * 100 + c * 50
            if total == num:
                count += 1

print(count)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int inH = stdin.nextInt();
		int inW = stdin.nextInt();
		int max = inH * inW;

		int inD = stdin.nextInt();

		int[] ah = new int[max];
		int[] aw = new int[max];
		for (int h = 1; h <= inH; h++) {
			for (int w = 1; w <= inW; w++) {
				int inA = stdin.nextInt();
				ah[inA - 1] = h;
				aw[inA - 1] = w;
			}
		}

		int[] pow = new int[max];
		for (int a = inD; a < max; a++) {
			pow[a] = pow[a - inD] + Math.abs(ah[a] - ah[a - inD]) + Math.abs(aw[a] - aw[a - inD]);
		}

		int inQ = stdin.nextInt();
		for (int i = 0; i < inQ; i++) {
			int inL = stdin.nextInt();
			int inR = stdin.nextInt();

			System.out.println(pow[inR - 1] - pow[inL - 1]);
		}
	}
}


Measured memory_bytes: 90288
fun next(player: Char, cards: StringBuilder): Char {
    if (cards.isEmpty()) {
        return player
    }
    val next = cards[0]
    cards.deleteCharAt(0)
    return next
}

fun main(args: Array<String>) {
    val sa = StringBuilder(readLine())
    val sb = StringBuilder(readLine())
    val sc = StringBuilder(readLine())
    var current = 'a'
    loop@ while (true) {
        when (current) {
            'a' -> current = next('A', sa)
            'b' -> current = next('B', sb)
            'c' -> current = next('C', sc)
            else -> break@loop
        }
    }
    println(current)
}


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

int main() {
  int n, r;
  cin >> n >> r;
  
  if (n >= 10){
    cout << r << endl;
  }
  else{
    int a = r + 100 * (10 - n);
    cout << a << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000+5
#define NIL -1

struct Node {
	int p, l, r;
}; 

Node T[MAX];
int n, D[MAX];

void print(int u) {
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";
	
	if ( T[u].p == NIL ) cout << "root, ";
	else if ( T[u].l == NIL ) cout << "leaf, ";
	else cout << "internal node, ";
	
	cout << "[";
	for (int i = 0, c = T[u].l ; c != NIL; i++, c = T[c].r ) {
		if ( i ) cout << ", ";
		cout << c;
	}
	cout << "]" << endl;
}

//递归求深度 
int rec(int u, int p) {
	D[u] = p;
	if ( T[u].r != NIL ) rec(T[u].r, p);       //右侧兄弟设置为相同深度 
	if ( T[u].l != NIL ) rec(T[u].l, p + 1);   //最左侧子结点的深度设为自己深度 + 1 
}

int main() {
	int i, j, d, v, c, l, r;
	cin >> n;
	for ( int i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;
	for ( int i = 0; i < n; i++ ) {
		cin >> v >> d;
		for ( int j = 0; j < d; j++ ){
			cin >> c;
			if ( j == 0 ) T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	for ( i = 0; i < n; i++ ) {
		if ( T[i].p == NIL ) r = i;
	}
	rec(r, 0);
	
	for ( int i = 0; i < n; i++ ) print(i);
	
	return 0;
} 


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

int main() {
	int n;
	while(cin >> n, n) {
		for(int i = 0; i < n; i++) {
			int pm,pe,pj;
			cin >> pm >> pe >> pj;
			if(pm == 100 || pe == 100 || pj == 100)
				cout << "A" << endl;
			else if(pm + pe >= 180)
				cout << "A" << endl;
			else if(pm + pe + pj >= 240)
				cout << "A" << endl;
			else if(pm + pe + pj >= 210)
				cout << "B" << endl;
			else if(pm + pe + pj >= 150 && (pm >= 80 || pe >= 80))
				cout << "B" << endl;
			else
				cout << "C" << endl;
		}
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int p[100000], y[100000];
    vector<int> yd[100001];
    rep(i, m) {
        scanf("%d%d", &p[i], &y[i]);
        yd[p[i]].push_back(y[i]);
    }
    rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end()); //ydの添字pが1スタートだから+1してる。県の数n回繰り返す。
    // %0桁数d
    // lower_bound(yd[p[0]].begin(), yd[p[0]].end(), y[0]) は、探索したい値y[0]以上が現れる最初の位置のイテレータを取得。イテレータなので+1してる
    rep (i, m) {
        printf("%012lld\n", ll(p[i]) * 1000000 + int(lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin()) + 1);
    }
    return 0;
}

Measured memory_bytes: 9904
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		StringBuffer S_temp =new StringBuffer(S);
		String S_r = new String(S_temp.reverse());
		int N = S.length();
		StringBuffer s1_temp = new StringBuffer(S.substring(0, (N - 1) / 2));
		String s1 = new String(s1_temp);
		String  s1_r = new String(s1_temp.reverse());
		StringBuffer s2_temp = new StringBuffer(S.subSequence((N + 3) / 2 - 1, N));
		String s2 = new String(s2_temp);
		String  s2_r = new String(s2_temp.reverse());
		if(S.equals(S_r) && s1.equals(s1_r) && s2.equals(s2_r)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
int main() {
    int nmax=200000;
    int dp[nmax+1];
    for (int i=1;i<=nmax;i++) {
        if (i<=9) {
            dp[i]=i;
            continue;
        }
        dp[i]=dp[i-1];
        int a=i,n=1;
        while (a>9) {
            a/=10;
            n++;
        }
        int b=i%10;
        if (b==0)
            continue;
        int s=1;
        for (int j=0;j<(n-2);j++) {
            dp[i]+=2*s;
            s*=10;
        }
        if (a>b)
            dp[i]+=2*s;
        if (a==b)
            dp[i]+=2*((i-a*10*s)/10+1)+1;
    }
    int n;
    cin>>n;
    cout<<dp[n]<<endl;
}



Measured memory_bytes: 1024
import sys
from collections import deque
from itertools import accumulate
from bisect import bisect_right

sys.setrecursionlimit(4100000)

def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = [0] + list(accumulate(A))
    D = [0] + list(accumulate(B))
    if sum(A) + sum(B) <= K:
        print(N+M)
        exit()
    
    cnt = 0
    for i in range(N+1):
        tmp_cnt = i
        tmp_ans = C[i]
        if tmp_ans > K:
            break
        tmp_index = bisect_right(D, K-tmp_ans) -1
        tmp_cnt += tmp_index
        cnt = max(cnt,tmp_cnt)



    print(cnt)





if __name__ == "__main__":
    main()

Measured memory_bytes: 50924
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

bool CanMakeProgression(vector<int> progression)
{
	for (int i = 0; i < progression.size(); ++i)
	{
		if (progression[i] > i + 1)return false;
	}
	return true;
}


int main()
{
	int N;
	cin >> N;
	vector<int> b = vector<int>(N);
	vector<int>ret;
	for (int i = 0; i < N; ++i)cin >> b[i];

	if (CanMakeProgression(b))
	{
		for (int i = 0; i < N; ++i)
		{
			for (int j = N - i; j > 0; --j)
			{
				if (b[j - 1] == j)
				{
					ret.push_back(j);
					b.erase(b.begin() + (j - 1));
					break;
				}
			}
		}

		for (int i = 0; i < N; ++i)
			cout << ret[N - 1 - i] << endl;
	}
	else
	{
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
    }
    
    //解答処理
    private String solve() {
        String answer = "No";
        
        if (1 <= N && N <= 9) {
        	answer = "Yes";
        } else if (N % 2 == 0 && 2 <= N && N <= 18) {
        	answer = "Yes";
        } else if (N % 3 == 0 && 3 <= N && N <= 27) {
        	answer = "Yes";
        } else if (N % 4 == 0 && 4 <= N && N <= 36) {
        	answer = "Yes";
        } else if (N % 5 == 0 && 5 <= N && N <= 45) {
        	answer = "Yes";
        } else if (N % 6 == 0 && 6 <= N && N <= 54) {
        	answer = "Yes";
        } else if (N % 7 == 0 && 7 <= N && N <= 63) {
        	answer = "Yes";
        } else if (N % 8 == 0 && 8 <= N && N <= 72) {
        	answer = "Yes";
        } else if (N % 9 == 0 && 9 <= N && N <= 81) {
        	answer = "Yes";
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35652
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let mut lucas: Vec<i64> = vec![2, 1];
    for _i in 0..85 {
        let m = lucas.len();
        let l1 = lucas[m - 1];
        let l2 = lucas[m - 2];
        lucas.push(l1 + l2);
    }
    println!("{}", lucas[n]);
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2



//Segtree
ll def = inf;
const int MAX_N = 1 << 18;
ll n, dat[2 * MAX_N - 1];

ll comp(ll a, ll b) {
	return min(a, b);
}

void init(ll n_) {
	n = 1;
	while (n < n_) {
		n *= 2;
	}
	rep(i, 0, 2 * n - 1)dat[i] = (1LL<<31)-1;
}
void update(ll k,ll a) {
	k += n - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = comp(dat[2*k+1],dat[2*k+2]);
	}
}
ll query(int a,int b,int k,int l,int r){
	if (r <= a || b <= l)return def;
	if (a <= l && r <= b)return dat[k];
	else {
		ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return comp(vl, vr);
	}
}
ll get(ll a,ll b) {
	return query(a,b+1,0,0,n);
}
//endSegtree


int main(){
	int N, Q;
	cin >> N >> Q;
	init(N);

	rep(i, 0, Q) {
		ll c, x, y;
		cin >> c >> x >> y;
		if (c) {
			cout << get(x, y) <<endl;
		}
		else {
			update(x,y);
		}
	 }

	return 0;
}




Measured memory_bytes: 5140
<?php

$input = fgets(STDIN);
list($H, $W) = explode(' ', $input);

for ($i = 0; $i < $H; $i++) {
    $line = fgets(STDIN);

    $x = 2;
    while ($x > 0) {
        for ($j = 0; $j < $W; $j++) {
            echo "$line[$j]";
        }
        echo "\n";
        $x--;
    }
}


Measured memory_bytes: 3576
def main():
    s = int(input())

    def f(x):
        if x % 2 == 0:
            return x // 2
        return 3 * x + 1

    a = s
    cnt = 1
    memo = set()
    memo.add(a)
    while True:
        a = f(a)
        cnt += 1
        if a in memo:
            break
        memo.add(a)
    print(cnt)


main()


Measured memory_bytes: 3060