akhauriyash/Code-Regression huggingface dataset:
#coding: utf-8
amount = int(input())
strings = list(map(str, [input() for i in range(amount)]))
sum = 0
sum2 = 0

for i in range(len(strings)):
	# print(strings[i])
	abc = list(strings[i])
	abc.sort()
	strings[i] = ''.join(abc)
	# print(strings[i])

strings.sort()

for j in range(len(strings)-1):
	# print(j+1)
	# print(strings[j]+strings[j+1])
	if strings[j] == strings[j+1]:
		sum2 = sum2+1
	else:
		sum = sum + sum2 * (sum2+1) / 2
		sum2 = 0

sum = sum + sum2 * (sum2+1) / 2
print(int(sum))


Measured memory_bytes: 11036
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

d = l()

d.sort()

a = [0 for i in range(24)]
a[0] += 1

for i in range(n):
    if i % 2 == 0:
        a[d[i]] += 1
    else:
        if d[i]:
            a[24 - d[i]] += 1
        else:
            a[0] += 1

co = 12

for i in range(24):
    if a[i] >= 2:
        co = 0
        break
    for j in range(i+1,24):
        if a[i] >= 1 and a[j] >= 1:
            co = min(co,min(24-(j-i),j-i))
print(co)






Measured memory_bytes: 38516
#include <stdio.h>
int main(void)
{
    int i,N,j,d[110] = {110},m,c = 0;
    scanf("%d",&N);
    for(i = 1;i <= N;i++){
        scanf("%d",&d[i-1]);
    }
    for(i = 1;i <= N;i++){
        m = d[i-1];
        for(j = 1;j <= N;j++){
            if(m == 110)break;
            if(m == d[j-1]) d[j-1] = 110;
        }
        if(m != 110) c++;
    }
    printf("%d",c);
	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)

string s, t;
int main()
{
	cin >> s >> t;

	bool flag1 = false;
	RREP(i, 0, s.size() - t.size() + 1) {
		bool flag2 = false;
		REP(j, 0, t.size()) {
			if (s[i + j] == t[j] || s[i+j] == '?') {
				flag2 = true;
			}
			else {
				flag2 = false;
				break;
			}
		}

		if (flag2) {
			flag1 = true;
			REP(j, 0, t.size()) {
				s[i + j] = t[j];
			}
			break;
		}
	}


	if (!flag1) cout << "UNRESTORABLE" << endl;
	else {
		REP(i, 0, s.size()) {
			if (s[i] == '?') cout << "a";
			else cout << s[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a = list(map(int, input().split()))

num00 = a[3]-a[1]
num01 = a[2]-a[0]
ans = ['U']*num00
ans += ['R']*num01
ans += ['D']*num00
ans += ['L']*num01

ans += ['L']
ans += ['U']*(num00+1)
ans += ['R']*(num01+1)
ans += ['D']

ans += ['R']
ans += ['D']*(num00+1)
ans += ['L']*(num01+1)
ans += ['U']

print(*ans, sep='')


Measured memory_bytes: 9624
'use strict';
const p = s => console.log(s);
// let a,b,c,d;
// [a,b,c,d] = input[0].trim().split(" ").map(i => parseInt(i));

function main(input) {
  let A,B,C,K;
  [A,B,C,K] = input[0].trim().split(" ").map(i=> parseInt(i));

  let max =0;
  let flag = false;

  if(!flag) {
    if(A <= K) {
      max += A;
      K -= A;
    } else {
      max = K;
      flag = true;
    }
  }

  if(!flag) {
    if(B <= K) {
      K -= B;
    } else {
      flag = true;
    }
  }

  if(!flag) {
    max -= K;
  }

  p(max);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


Measured memory_bytes: 29620
#include<stdio.h>

main(void)
{
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a<b) {
		if(b<c) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
import java.util.*;
import java.io.*;
public class Main
{
  public static void main(String args[])throws Exception
  {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pw=new PrintWriter(System.out);
    int r=Integer.parseInt(br.readLine());
    pw.println(Math.PI*r*2);
    pw.flush();
    pw.close();
  }
}

Measured memory_bytes: 33344
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int N;
    long long K;
    cin>>N>>K;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;
    vector<int> F(N);
    for (int &f: F)
        cin>>f;

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

    auto check = [&](long long x)
    {
        long long k = 0;
        for (int i=0; i<N; i++)
            k += max(0LL, A[i]-x/F[N-i-1]);
        return k<=K;
    };

    long long ans = 1LL<<62;
    for (long long b=1LL<<61; b>0; b/=2)
        if (check(ans-b))
            ans -= b;
    if (check(0))
        ans = 0;
    cout<<ans<<endl;
}


Measured memory_bytes: 1920
#include<iostream>
using namespace std;
#include<string.h>
int main(){
	int c=0,i,n;
	char a[10],b[10],z[100];
	cin>>a>>n;
	for(i=0;i<n;i++){
		cin>>b;
		strcpy(z,b);
		strcat(z,b);
		if(strstr(z,a))
		c++;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3080
# -*- coding: utf-8 -*-

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        d = int(tokens[1])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        d = int(tokens[1])

    xs = []
    for i in range(1, n+1):
        tokens = lines[i].split(" ")
        xs.append([int(e) for e in tokens])

    return (n, d, xs)


def solve(n, d, xs):

    count = 0
    for i in range(n-1):
        for j in range(i+1, n):
            a = xs[i]
            b = xs[j]
            sum = 0
            for k in range(d):
                sum = sum + (a[k] - b[k])**2
            
            distance = math.sqrt(sum)

            if distance.is_integer():
                count = count + 1

    return count


def main():
    # 出力

    print("%s" % solve(*parse_input()))

#    solve(*parse_input())

if __name__ == '__main__':

    main()


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long ans;
        if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
            ans = 0;
        } else {
            long[] arr = {a, b, c};
            Arrays.sort(arr);
            ans = arr[0] * arr[1];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 9940
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <array>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;
typedef long long ll;
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template < typename T >
ostream& operator<<(ostream& os, vector< T >& v) {
    os << "{";
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i < v.size() - 1 ? ", " : "");
    }
    os << "}";
    return os;
}
// pair出力
template < typename T, typename U >
ostream& operator<<(ostream& os, pair< T, U >& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template < typename T, typename U >
ostream& operator<<(ostream& os, map< T, U >& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template < typename T >
ostream& operator<<(ostream& os, set< T >& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#pragma endregion

/////////////////////////////////////////

int main() {
    string s;cin >> s;
    for (int i = 0; i < 3; i++) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}

/////////////////////////////////////////

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>city(n);
  rep(i,n)cin>>city[i];
  int l,q;
  cin>>l>>q;
  int nl=n,c=0;
  while(nl>0){c++;nl/=2;}
  vector<vector<int>>db(n,vector<int>(c,n));
  int r=0;
  rep(i,n)
  {
    while(r+1<n&&city[r+1]<=city[i]+l)r++;
    db[i][0]=r;
  }
  rep(i,c-1)
  {
    rep(j,n)
    {
      db[j][i+1]=db[db[j][i]][i];
    }
  }
  rep(i,q)
  {
    int a,b;
    cin>>a>>b;
    a--;b--;
    if(a>b)swap(a,b);
    int cnt=0;
    int tc=c;
    while(1)
    {
      auto itr=lower_bound(db[a].begin(),db[a].begin()+tc,b);
      tc=itr-db[a].begin();
      if(itr==db[a].begin()){cnt++;break;}
      cnt+=(1<<(itr-db[a].begin()-1));
      a=*(itr-1);
    }
    cout<<cnt<<"\n";

  }
  cout<<flush;


  return 0;

}


Measured memory_bytes: 11392
#include <stdio.h>

class Dice2{
public:
	Dice2(){
		number = new int[6];
		relative = new int[55];
		relative[31] = relative[43] = relative[24] = relative[12] = 0;
		relative[3] = relative[20] = relative[52] = relative[35] = 1;
		relative[1] = relative[40] = relative[54] = relative[15] = 2;
		relative[4] = relative[10] = relative[51] = relative[45] = 3;
		relative[2] = relative[30] = relative[53] = relative[25] = 4;
		relative[21] = relative[42] = relative[34] = relative[13] = 5;
 	};
	~Dice2(){
		delete[] number;
		delete[] relative;
	};

	void setNumber(int index,int num){
		number[index] = num;
	};

	int returnRight(int top,int front){
		int top_index,front_index;
		for(int i = 0; i < 6; i++){
			if(number[i] == top)
				top_index = i;
			if(number[i] == front)
				front_index = i;
		}
		return number[relative[10*top_index+front_index]];
	}
private:
	int* number;
	int* relative;
};

int main(){
	Dice2 dice2;
	int x,q,top,front;
	for(int i = 0; i < 6; i++){
		scanf("%d",&x);
		dice2.setNumber(i,x);
	}
	scanf("%d",&q);
	for(int i = 0; i < q; i++){
		scanf("%d %d",&top,&front);
		printf("%d\n",dice2.returnRight(top,front));
	}
}



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

long long hush[100009], power[100009], maxn; string S;

long long substring(int l, int r) {
	return (hush[l] * power[r - l] - hush[r]);
}
long long solve(int p) {
	if (p > S.size()) return -p;
	vector<long long>E;
	for (int j = 0; j <= S.size() - p; j++) E.push_back(substring(j, j + p));
	sort(E.begin(), E.end());
	E.erase(unique(E.begin(), E.end()), E.end());
	return E.size();
}

int main() {
	cin >> S;
	power[0] = 1; for (int i = 1; i <= 100000; i++) power[i] = (power[i - 1] * 29LL);
	for (int i = 1; i <= S.size(); i++) hush[i] = (hush[i - 1] * 29LL + (S[i - 1] - 'a' + 1));

	int le = 1, ri = S.size() + 3, c1, c2;

	for (int i = 0; i < 40; i++) {
		c1 = (le + le + ri) / 3;
		c2 = (le + ri + ri) / 3;
		long long G1 = solve(c1);
		long long G2 = solve(c2);
		maxn = max(maxn, G1);
		maxn = max(maxn, G2);
		if (G1 < G2) le = c1;
		if (G1 >= G2) ri = c2;
	}
	cout << maxn << endl;
	return 0;
}

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

int my, mx, y, x;
char grid [1001][1001];
int dp [1001][1001];

int main ()
    {
    scanf ("%d%d",&my,&mx);
    for (y=1; y<=my; y++)
        scanf ("%s",grid[y]+1);
    dp[0][1]=1;
    for (y=1; y<=my; y++)
        for (x=1; x<=mx; x++)
            if (grid[y][x]=='.')
                dp[y][x]=(dp[y-1][x]+dp[y][x-1])%1000000007;
    printf ("%d\n",dp[my][mx]);
    return 0;
    }


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


class Dice{
    public : int diceNum[6];

    public : void set(int Num,int label){
        diceNum[label] = Num;
    };

    public : void roll(char label){
        switch (label)
        {
        case 'E':
            setAll(diceNum[3],diceNum[1],diceNum[0],diceNum[5],diceNum[4],diceNum[2]);
            break;
        case 'N':
            setAll(diceNum[1],diceNum[5],diceNum[2],diceNum[3],diceNum[0],diceNum[4]);
            break;
        case 'S':
            setAll(diceNum[4],diceNum[0],diceNum[2],diceNum[3],diceNum[5],diceNum[1]);
            break;
        case 'W':
            setAll(diceNum[2],diceNum[1],diceNum[5],diceNum[0],diceNum[4],diceNum[3]);
            break;
        }
    };
    public : int upNum(){
        return diceNum[0];
    }
    public : int frontNum(){
        return diceNum[1];
    }
    public : int rightNum(){
        return diceNum[2];
    }
    
    public : int Num(int Num){
        return diceNum[Num];
    }


    private : void setAll(int a1,int a2,int a3,int a4,int a5,int a6){
        set(a1,0);
        set(a2,1);
        set(a3,2);
        set(a4,3);
        set(a5,4);
        set(a6,5);
    };
};


bool Checker(Dice diceA,Dice diceB){
    bool check = true;
    for(int i=0;i<6;i++){
        if(diceA.Num(i) != diceB.Num(i)){
            check = false;
        }
    }
    return check;
}

int main(){
    

    Dice diceA,diceB;

    for(int i = 0;i<6;i++){
        int diceNum;
        scanf("%d",&diceNum);
        diceA.set(diceNum,i);
    }
    for(int i = 0;i<6;i++){
        int diceNum;
        scanf("%d",&diceNum);
        diceB.set(diceNum,i);
    }

    bool check = false;
    
    //printf("  %d %d %d %d %d %d\n",diceB.diceNum[0],diceB.diceNum[1],diceB.diceNum[2],diceB.diceNum[3],diceB.diceNum[4],diceB.diceNum[5]);




    //printf("                                                                   %d %d\n",checkNum[0],checkNum[1]);
    for(int j = 0;j < 4;j++){
        //printf("  %d %d %d %d %d %d\n",diceB.diceNum[0],diceB.diceNum[1],diceB.diceNum[2],diceB.diceNum[3],diceB.diceNum[4],diceB.diceNum[5]);

        if(diceA.frontNum() == diceB.frontNum()){
            break;
        }
        diceB.roll('S');
    }

    if(diceA.frontNum() != diceB.frontNum()){
        diceB.roll('W');
        diceB.roll('S');
        //printf("                                                                   %d\n",dice.frontNum());
        if(diceA.frontNum() != diceB.frontNum()){
            diceB.roll('S');
            diceB.roll('S');
        }
    }

    //printf("  %d %d %d %d %d %d\n",diceB.diceNum[0],diceB.diceNum[1],diceB.diceNum[2],diceB.diceNum[3],diceB.diceNum[4],diceB.diceNum[5]);

    if(diceA.frontNum() != diceB.frontNum()){
        printf("No\n");
        return 0;
    }

    for(int i = 0;i< 4;i++){
        diceB.roll('W');
        if(Checker(diceA,diceB)){
            printf("Yes\n");
            return 0; 
        }
    }

    printf("No\n");




    return 0;
}



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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

struct Diag{
    int h, w, d;
    Diag( int h, int w ) : w( w ), h( h ){
        d = w * w + h * h;
    }

    bool operator< ( const Diag& rhs ) const {
        if( d < rhs.d ) return true;
        if( d > rhs.d ) return false;
        return h < rhs.h;
    }
};

signed main(){
    vector<Diag> rect;
    REPONE( i, 150 ){
        FOR( j, i + 1, 151 ){
            rect.emplace_back( i, j );
        }
    }

    sort( ALL( rect ) );

    int H, W;
    while( cin >> H >> W, H | W ){
        Diag in = Diag( H, W );
        in = *( ++lower_bound( ALL( rect ), in ) );
        cout << in.h << " " << in.w << endl;
    }

}



Measured memory_bytes: 3260
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
	//return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow
	//return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数

//素数判定
template<typename T>
bool IsPrime(T num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
//vector<vector<int>> data(3, vector<int>(4));
//vector<vector<Type>> vv(n);

int main() {
	ll A, B, ans = 1;cin >> A >> B;
	vector<ll>sum;
	vector<vector<ll>> s;
	ll L = gcd(A, B);
	if (IsPrime(L) == 1) {
		cout << 2 << endl;
	}
	else {
		ll i = 1;
		while (1) {
			if (L % i == 0) {
				L /= i;
				if (IsPrime(i)) ans++;
			}
			if (i > L)break;
			i++;
			if (i > 10000000) {
				ans++;
				break;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(input())
    a, b = map(int, input().split())
    for i1 in range(a, b + 1):
        if i1 % k == 0:
            print('OK')
            sys.exit()
    print('NG')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
string s;
int main(){
	ll i,md=0;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		md=(md+(s[i]-'0'))%9;
	}
	if(md==0)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}

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


bool ac[100005];
int wa[1000005];


int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, m;
	cin >> n >> m;
	int ac_cnt = 0, penalty = 0;

	for (int i = 1; i <= m; ++i){
		int x;
		string s;
		cin >> x >> s;
		if (s == "AC"){
			if (!ac[x]){
				ac[x] = true;
				ac_cnt++;
				penalty += wa[x];
			}
		}
		else{
			wa[x]++;
		}
	}

	cout << ac_cnt << " " << penalty << "\n";
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int K;
    cin >> K;
    int A,B;
    cin >> A >> B;
    FOR(i,A,B+1){
        if(i%K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

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

int main(){ 
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
} 

Measured memory_bytes: 256
import java.util.*;
public class Main{
	private static Scanner scan = new Scanner(System.in);
	public static void train(){
		int N = scan.nextInt(), i = scan.nextInt();
		System.out.println(N-i+1);
	}
	public static void gritCompression(){
		int H = scan.nextInt(), W = scan.nextInt();
		char[][] array = new char[H][W];
		
		//入力
		for(int i=0;i<H;i++){
			array[i] = scan.next().toCharArray();
		}
		System.out.println();
		
		ArrayList<Integer> line = new ArrayList<>(); //出力しない列
		ArrayList<Integer> row = new ArrayList<>();  //出力しない行
		
		//行のみ見る
		for(int i=0;i<H;i++){
			boolean flag = false;
			for(int j=0;j<W;j++){
				if(array[i][j]=='#'){
					flag = true;
					break;
				}
			}
			if(flag){row.add(i);}
		}
		
		//列を見る．
		for(int j=0;j<W;j++){
			boolean flag = false;
			for(int i=0;i<H;i++){
				if(array[i][j]=='#'){
					flag = true;
					break;
				}
			}
			if(flag){
				line.add(j);
			}
		}
		
		//出力
		for(int i=0;i<H;i++){
			if(row.contains(i)){
				for(int j=0;j<W;j++){
					if(line.contains(j)){
						System.out.print(array[i][j]);
					}
				}
				System.out.println();
			}
		}
	}
	
	public static void main(String[] argv){
		gritCompression();
	}
}

Measured memory_bytes: 26304
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        resultCheck rc = new resultCheck();
        Scanner sc = new Scanner(System.in);
        while(true){
            int tyukanTest  = sc.nextInt();
            int kimatsuTest = sc.nextInt();
            int againTest   = sc.nextInt();
            if(tyukanTest == -1 && kimatsuTest == -1 && againTest == -1){
                break;
            }
            System.out.println(rc.judgeTest(tyukanTest, kimatsuTest, againTest));
        }
    }
}

class resultCheck{
    public String judgeTest(int tyukanTest, int kimatsuTest, int againTest){
        if(tyukanTest == -1 || kimatsuTest == -1){
            tyukanTest = 0;
            kimatsuTest = 0;
        }
        if(tyukanTest + kimatsuTest >= 80){
            return "A";
        }
        else if(tyukanTest + kimatsuTest >= 65){
            return "B";
        }
        else if(tyukanTest + kimatsuTest >= 50){
            return "C";
        }
        else if(againTest >= 50){
            return "C";
        }
        else if(tyukanTest + kimatsuTest >= 30){
            return "D";
        }
        else{
            return "F";
        }
    }
}


Measured memory_bytes: 26336
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string s;

int main() {
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7')
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 3620
N, M, Q = map(int, input().split())
X = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
    L, R = map(int, input().split())
    X[L][R] += 1

# for i in range(N):
#     for j in range(N):
#         X[i+1][j+1] += X[i][j+1] + X[i+1][j]
# print(*X, sep='\n')
# print('')

for i in range(N+1):
    for j in range(N):
        X[i][j+1] += X[i][j]

for i in range(N+1):
    for j in range(N):
        X[j+1][i] += X[j][i]
# print(*X, sep='\n')

ans = []
for _ in range(Q):
    p, q = map(int, input().split())
    ans.append(X[q][q] - X[q][p-1] - X[p-1][q] + X[p-1][p-1])

print(*ans, sep='\n')

Measured memory_bytes: 68184
# ABC075 B - Minesweeper
H,W = map(int,input().split())

G = [['' for _ in range(W+2)] for _ in range(H+2)]
Ans = [[0 for _ in range(W+2)] for _ in range(H+2)]

for i in range(1,H+1):
    S = input()
    for j,s in enumerate(S):
        G[i][j+1]= s

for i in range(1,H+1):
    for j in range(W):
        # 1行目
        if i == 1:
            if G[i][j+2] == '#':
                Ans[i][j+1] += 1
            # if G[i][j+1] == '#':
            #     Ans[i][j+1] = '#' 
            if G[i][j] == '#':
                Ans[i][j+1] += 1
            if G[i+1][j+2] == '#':
                Ans[i][j+1] += 1
            if G[i+1][j+1] == '#':
                Ans[i][j+1] += 1
            if G[i+1][j] == '#':
                Ans[i][j+1] += 1
            continue
        # 最終行
        if i == H:
            if G[i][j+2] == '#':
                Ans[i][j+1] += 1
            # if G[i][j+1] == '#':
            #     Ans[i][j+1] = '#' 
            if G[i][j] == '#':
                Ans[i][j+1] += 1
            if G[i-1][j+2] == '#':
                Ans[i][j+1] += 1
            if G[i-1][j+1] == '#':
                Ans[i][j+1] += 1
            if G[i-1][j] == '#':
                Ans[i][j+1] += 1
            continue

        if G[i][j+2] == '#':
            Ans[i][j+1] += 1
        # if G[i][j+1] == '#':
        #     Ans[i][j+1] = '#' 
        if G[i][j] == '#':
            Ans[i][j+1] += 1
        if G[i+1][j+2] == '#':
            Ans[i][j+1] += 1
        if G[i+1][j+1] == '#':
            Ans[i][j+1] += 1
        if G[i+1][j] == '#':
            Ans[i][j+1] += 1 
        if G[i-1][j+2] == '#':
            Ans[i][j+1] += 1
        if G[i-1][j+1] == '#':
            Ans[i][j+1] += 1
        if G[i-1][j] == '#':
            Ans[i][j+1] += 1

for i in range(1,H+1):
    for j in range(1,W+1):
        Ans[i][j] = str(Ans[i][j])
        if G[i][j] == '#':
            Ans[i][j] = '#'

for i in range(1,H+1):
    s = ''
    for j in range(1,W+1):
        s += Ans[i][j]
    print(s)

Measured memory_bytes: 3192
// 3_abc140_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1){
        cin >> b[i];
    }

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

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


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 998244353 
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

vector <int> ans[100000];
int n;

int main() {
	cin >> n;
	int num = sqrt(n * 2);
	if (num * (num + 1) != 2 * n) {
		cout << "No" << endl;
		return 0;
	}
	int cc = num;
	for (int i = 0; i < num; i++) ans[0].push_back(i);
	for (int i = 1; i < num + 1; i++) {
		for (int j = 0; j < i; j++) ans[i].push_back(ans[j][i - 1]);
		for (int j = i; j < num; j++) ans[i].push_back(cc++);
	}
	cout << "Yes" << endl;
	cout << num + 1 << endl;
	for (int i = 0; i < num + 1; i++) {
		cout << num << " ";
		for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] + 1 << " ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
//mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9+7, N = 2e5+5;

int a[N], n, m, k;

void solve(int test_case){
	int i, j;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}int ans = 0;
	sort(a, a+n);
	for(i=0;i<n-2;i++){
		for(j=i+1;j<n-1;j++){
			for(k=j+1;k<n;k++){
				if(a[i]==a[j]||a[j]==a[k]||a[i]==a[k])continue;
				if(a[i]+a[j]<=a[k])continue;
			//	cout << a[i] << ' ' << a[j] << ' ' << a[k] << '\n';
				ans++;
			}
		}
	}cout << ans;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}



Measured memory_bytes: 3692
#include<iostream>
using namespace std;
int main()
{
	char a[6];
	for(int i = 0;i<6;i++)
	{
		cin>>a[i];
	}
	for(int i = 0;i<3;i++)
	{
		if(a[i] != a[5-i])
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

main :-
    get_number(A),
    get_number(B),
    (A mod 2 =:= B mod 2) -> (X is (A + B) div 2, writeln(X)) ; writeln("IMPOSSIBLE").


Measured memory_bytes: 8188
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long a[10001] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    long long min = 1000000, max = -1000000, sum = 0;
    for(int i = 0; i < n; i++){
        if(a[i]<min){
            min = a[i];
        }
        if(a[i]>max){
            max = a[i];
        }
        sum= sum +a[i]; 
    }
    cout << min << " " << max << " " << sum <<endl;
}


Measured memory_bytes: 3168
import sys
n,m = map(int,input().split())
num = ['t'] * n

for i in range(m):
  j,x = map(int,input().split())
  if (j,x) == (1,0) and n != 1:
    print(-1)
    sys.exit()
  if num[j-1] == 't':
    num[j-1] = x
  elif num[j-1] != x:
    print(-1)
    sys.exit()
    
if (n,m) == (1,0):
  print(0)
  sys.exit()

for i in range(n):
  if i == 0 and num[i] == 't':
    num[0] = '1'
  elif num[i] == 't':
    num[i] = '0'
  else:
    num[i] = str(num[i])
    
print(''.join(num))   

Measured memory_bytes: 61988
#include<stdio.h>
int main(void){
  int N,X,L,sum=0,count=1;
  scanf("%d %d",&N,&X);
  for(int i=0;i<N;i++){
    scanf("%d",&L);
    sum+=L;
    if(sum<=X){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  int mat_num[H][W+2] = {};
  string sh,sm,sl,s0;
  for(int j=0;j<W+2;j++){
    s0+='.';
  }
  sh = s0;
  sm = s0;
  for(int i=0;i<H;i++){
    cin >> sl;
    sl = '.'+sl+'.';
    if(i>0){
      for(int j=1;j<W+1;j++){
        mat_num[i-1][j] =
          (sh.at(j-1)=='#')+(sh.at(j)=='#')+(sh.at(j+1)=='#')+
          (sm.at(j-1)=='#')+(sm.at(j)=='#')+(sm.at(j+1)=='#')+
          (sl.at(j-1)=='#')+(sl.at(j)=='#')+(sl.at(j+1)=='#');
        if(sm.at(j)=='#'){
          cout << '#';
        }else{
          cout << mat_num[i-1][j];
        }
      }
    }
    cout << endl;
    sh = sm;
    sm = sl;
    sl = s0;
    if(i==H-1){
      for(int j=1;j<W+1;j++){
        mat_num[i][j] =
          (sh.at(j-1)=='#')+(sh.at(j)=='#')+(sh.at(j+1)=='#')+
          (sm.at(j-1)=='#')+(sm.at(j)=='#')+(sm.at(j+1)=='#')+
          (sl.at(j-1)=='#')+(sl.at(j)=='#')+(sl.at(j+1)=='#');
        if(sm.at(j)=='#'){
          cout << '#';
        }else{
          cout << mat_num[i][j];
        }
      }
    }
  }
  return 0;
}


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

int main(){
    //500,100,50
    int A, B, C;
    cin >> A >> B >> C;

    int X;
    cin >> X;

    int count = 0;

    for (int i = 0; i < A + 1; i++) {
        for (int j = 0; j < B + 1; j++) {
            for (int k = 0; k < C + 1; k++) {
                int rem = X;
                rem -= 500 * i + 100 * j + 50 * k;
                if (rem == 0) count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
 
using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
int main () {
	ll K;
    cin >> K;
	bool cannot = false;
	for (int n = 50; n > 1; --n) {
		vector<ll> v(n);
		rep(i,n)
			v[i] = i + K/n;
		for (int i = 0; i < K%n; ++i) {
			v[i%n] += n;
			for (int j = 0; j < n; ++j) {
				if (j == i%n)
					continue;
				v[j]--;
				if (v[j] < 0) {
					cannot = true;
				}
			}
		}
		if (cannot == false) {
			cout << n << endl;
			rep(j,n) {
				cout << v[j] << " ";
			}
			cout << endl;
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 384
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;//toInt
    var height = fieldInfo[1] - 0;//toInt
   
    // 0 0が入力された
    if(!width && !height){
      break;
    }
   
    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    for(var ei = 0;ei < 5; ei++){
      elem[ei].length = 0;
    }
       
    for(var y = 0; y < height; y++){
      i++;//1行進める
      for(var x = 0; x < width; x++){
        var c = input[i][x];
   
        switch(c){
        case 'S':
          start = pos(x, y);
          break;
        case 'G':
          goal = pos(x, y);
          break;
        case '.':
          break;
        default : // 入力値が正しいので、絶対に属性
          elem[c - 1][elem[c - 1].length] = pos(x, y);
          break;
        }
      }
    }
   
    var INF = 1 << 30;
    var bestElement = -1;
    var distance = INF;
       
    // 属性ごとにループ
    for (var startElem = 0; startElem < 5; startElem++) {
      // DPの初期化 DP[属性][同じ属性内の連番]
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          dp[h][hidx] = INF;
        }
      }
         
      // 最初に選んだパチモンから次に捕まえられる属性番号
      var first = (startElem + 1) % 5;
   
      var firstLength = elem[first].length;
      for (var j = 0; j < firstLength; j++) {
        // s→e1を計算
        dp[first][j] = dist(start, elem[first][j]);
      }
         
      // s->1->2->3->4->g
      // なので、ループは間の-> * 3分まわす
      for (var e = 0; e < 3; e++) {
        // ex->e(x+1)
        var now = (first + e) % 5;
        var next = (now + 1) % 5;
        var nowLength = elem[now].length;
        var nextLength = elem[next].length;
        for (var j = 0; j < nowLength; j++) {
          for (var k = 0; k < nextLength; k++) {
            dp[next][k] = fmin(
              dp[next][k],
              dp[now][j] + 
                  dist(elem[now][j], elem[next][k]));
          }
        }
      }
         
      var last = (first + 3) % 5;
      var lastLength = elem[last].length;
      for (var j = 0; j < lastLength; j++) {
        // e4->g
        var d = dp[last][j] + 
                    dist(elem[last][j], goal);
           
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
           
      }
         
    }
       
    if (distance == INF) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }
   
    i++;
  }
     
   
}
   
function dist(from, to){
  return fabs((from >> 11) - (to >> 11)) + fabs((from & 2047) - (to & 2047));
}
   
function fmin(a, b){
 return b + ((a-b) & ((a-b) >> 31));
}
   
function pos(a, b){
  // 2^10 = 1024なので、下位10ビットでy座標を、上位ビットでx座標を表す
  return (a << 11) + b;
}
  
function fabs(a){
 var mask = a >> 31;
 return (a ^ mask) - mask;
}
   
var
input = '';
   
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 51448
#include <stdio.h>

int main(void)
{
    int a,b,c,e;
    e = 0;
    scanf("%d %d %d",&a,&b,&c);
    if(a >= 0 && a <= 10000 && b >= 0 && b <= 10000 && c >= 0 && c <= 10000){
        for(int i=0; i<2; i++){
            if(c < b){
                e = b;
                b = c;
                c = e;
            }
            if(b < a){
            e = a;
            a = b;
            b = e;
            }
        }
    }
    printf("%d %d %d\n",a,b,c);
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

const int N = 1e6+1;
int n, m, k;
vector <char> c[N];

struct Data{
  pii cur;
  int u, v, dir;
  Data(pii cur, int u, int v, int dir) : cur(cur), u(u), v(v), dir(dir) {}
};

void bfs(int U, int V, int X, int Y){
  deque <Data> Q;
  vector <vector <int>> dis[4];
  for (int i = 0; i < 4; i++){
    dis[i].assign(n + 1, vector <int> (m + 1, INF));
  } 
  for (int i = 0; i < 4; i++) dis[i][U][V] = 0;
  Q.push_back(Data(pii(0, 0), U, V, -1));
  
  while (Q.size()){
    Data orz = Q.front();
    Q.pop_front();
    int u = orz.u; int v = orz.v; 
    int dir = orz.dir; pii cur = orz.cur;
    for (int i = 0; i < 4; i++){
      int x = u + dx[i];
      int y = v + dy[i];
      if (x < 1 || x > n || y < 1 || y > m || c[x][y] == '@') continue;
      if (i == dir){
        if (cur.second == k){
          if (dis[i][x][y] > cur.first + 1){
            dis[i][x][y] = cur.first + 1;
            Q.push_back(Data(pii(dis[i][x][y], 1), x, y, i));
          }
        }
        else {
          if (dis[i][x][y] > cur.first){
            dis[i][x][y] = cur.first;
            Q.push_front(Data(pii(dis[i][x][y], cur.second + 1), x, y, i));
          }
        }
      }
      else {
        if (dis[i][x][y] > cur.first + 1){
          dis[i][x][y] = cur.first + 1;
          Q.push_back(Data(pii(dis[i][x][y], 1), x, y, i));
        }    
      }
    }
  }
  int res = INF;
  for (int i = 0; i < 4; i++){
    chmin(res, dis[i][X][Y]);
  }
  if (res == INF) cout << -1;
  else cout << res;
}

int main()
{
  fastio;
  cin >> n >> m >> k;
  int u, v, x, y; cin >> u >> v >> x >> y;
  for (int i = 1; i <= n; i++) c[i].resize(m + 1);
  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= m; j++){
      cin >> c[i][j];
    }
  }
  bfs(u, v, x, y);
  return 0;
}


Measured memory_bytes: 62744
# N = int(input())
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
time_ans = 0
A_sort = sorted(A)
before = -1
b = -1
for i in range(N):
        a_sorti = A_sort[i]
        if a_sorti == before:
                time_ans += b
                continue
        b = A_sort.index(a_sorti)
        time_ans += b
        before = a_sorti

for i in range(N - 1):
        for j in range(i + 1,N):
                if A[i] > A[j]:
                        ans += 1
ans1 = K * (K + 1) * time_ans // 2 - (time_ans - ans) * K
print(ans1 % (10 ** 9 + 7))

Measured memory_bytes: 3188
n, m, l = map(int, input().split())
a = [[0 for i in range(0, m)] for j in range(0, n)]
b = [[0 for i in range(0, l)] for j in range(0, m)]
c = [[0 for i in range(0, l)] for j in range(0, n)]
for i in range(0, len(a)):
	a[i] = list(map(int, input().split()))
for i in range(0, len(b)):
	b[i] = list(map(int, input().split()))
# print(a)
# print(b)
# print(c)
for i in range(0, len(c)):
	for j in range(0, len(c[i])):
		for k in range(0, m):
			c[i][j] = c[i][j] + a[i][k] * b[k][j]

for i in range(0, len(c)):
	for j in range(0, len(c[i])):
		if j != len(c[i]) - 1:
			print('{0} '.format(c[i][j]), end='')
		else:
			print(c[i][j])
# print(c)



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

int main(){
	int a,b;
	char op;
	while(1){
	cin>>a>>op>>b;
	if(op=='?'){
		break;
	}if(op=='+'){
		cout<<a+b<<endl;
	}if(op=='-'){
		cout<<a-b<<endl;
	}if(op=='*'){
		cout<<a*b<<endl;
	}if(op=='/'){
		cout<<a/b<<endl;
	}			
}
}
/*for(初期化式;条件式;終了のときの式)
  for(int i=a;i<=b;i++){
     cout<<i<<endl;
  }*/



Measured memory_bytes: 3088
import java.util.Scanner;

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

        if (t.startsWith(s) && s.length() + 1 == t.length()) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 26832
# coding: utf-8
import math
a, b = map(int, input().split())
ans = 1
now_consent = a
plusplug = a - 1
if b == 1:
  print(0)
elif a >= b:
    print(1)
elif a < b:
    other = b - a
    ans += math.ceil(other / plusplug)
    print(ans)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,sum=0;
  cin>>N;
  vector<int> t(N);
  for(int i=0;i<N;i++)
    cin>>t.at(i);
  cin>>M;
  vector<int> p(M);
  vector<int> x(M);
  for(int i=0;i<M;i++)
    cin>>p.at(i)>>x.at(i);
  for(int i=0;i<N;i++)
    sum+=t.at(i);
  for(int i=0;i<M;i++){
    int a=sum-t.at(p.at(i)-1)+x.at(i);
    cout<<a<<endl;
  }
}


Measured memory_bytes: 3624
n = gets.chomp.to_i
points = readlines.map{ |line| line.chomp.split.map(&:to_i) }
 
permutation = [*0..n-1].permutation(n).to_a

sum = 0

permutation.each do |root|
    distance = 0
    root.each_with_index do |point, index|
        if index != 0
            distance += Math.sqrt((points[point][0] - points[root[index-1]][0])**2 + (points[point][1] - points[root[index-1]][1])**2)
        end
    end
    sum += distance
end

puts sum / permutation.size

Measured memory_bytes: 8700
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long best, n, i, j, k, keep, retain, ss;
	cin >> n >> k;
	vector<long long> a(n + 1), s(n + 1);
	s[0] = 0;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
	}

	best = 0;
	for (keep = 0; keep <= n; keep++) {
		for (retain = 0; (retain <= (n - keep)) && (n - keep + retain <= k); retain++) {
			for (i = 1; i + keep - 1 <= n; i++) {
				priority_queue<long long> pq;
				for (j = 1; j < i; j++) pq.push(-a[j]);
				for (j = i + keep; j <= n; j++) pq.push(-a[j]);
				ss = s[i + keep - 1] - s[i - 1];
				for (j = 0; j < retain; j++) {
					ss -= pq.top();
					pq.pop();
				}
				best = max(best, s[n] - ss);
			}
		}
	}

	cout << best << "\n";

	return 0;
}


Measured memory_bytes: 256
#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;
 
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll mod(ll a, ll b) { return (a%b+b)%b; }
ll gcd(ll x, ll y) { return __gcd(x, y); }
ll lcm(ll x, ll y) { return x * 1ll * y / gcd(x, y); }
 
 
const ll MAXN = 1e9 + 9;
const ll SIZE = 1e5 + 5;
const ll MOD  = 1e9 + 7;

ll N, M, sum, A, B, C, cnt[SIZE];

int main() { speedhack()

	cin >> N;
	forn (i, N) {
		cin >> A;
		sum += A;
		++cnt[A];
	}

	cin >> M;
	forn (i, M) {
		cin >> B >> C;
		sum -= cnt[B] * B;
		sum += cnt[B] * C;

		cnt[C] += cnt[B];
		cnt[B] = 0;
		cout << sum << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 4380
def main():
    N, M = list(map(int, input().split(' ')))
    max_l, min_r = 1, N
    for _ in range(M):
        L, R = list(map(int, input().split(' ')))
        max_l = max([max_l, L])
        min_r = min([min_r, R])
    print(max([min_r - max_l + 1, 0]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def main():
    s = input()
    t = input()
    len_s = len(s)
    len_t = len(t)
    ans = 10 ** 12

    for i in range(len_s - len_t + 1):
        cnt = 0
        for j in range(len_t):
            if s[i + j] != t[j]:
                cnt += 1
        ans = min(ans, cnt)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67008