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

#define HW 500

int h, w;
int a[HW][HW];

typedef pair< int, int > P;
typedef pair< P, P > PP;
vector< PP > v;

int is_even( int n )
{
	if( (n % 2) == 0 ) {
		return 1;
	}
	return 0;
}

void next_c( int &y, int &x )
{
	int dir = 0;
	if( (y % 2) ) {
		dir = 1;
	}
	if( dir == 0 ) {
		x++;
		if( x >= w ) {
			x = x - 1;
			y++;
		}
	}
	else {
		x--;
		if( x < 0 ) {
			x = 0;
			y++;
		}
	}
}

void next_cc( int y, int x, int &yy, int &xx )
{
	int dir = 0;
	if( (y % 2) ) {
		dir = 1;
	}
	yy = y;
	if( dir == 0 ) {
		xx = x + 1;
		if( xx >= w ) {
			xx = xx - 1;
			yy = y + 1;
		}
	}
	else {
		xx = x - 1;
		if( xx < 0 ) {
			xx = 0;
			yy = y + 1;
		}
	}
}

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

	int y = 0, x = 0;
	for( int i = 0; i < h * w - 1; i++ ) {
		if( is_even( a[y][x] ) ) {
			next_c( y, x );
			continue;
		}

		int yy, xx;
		next_cc( y, x, yy, xx );
		v.push_back( make_pair( make_pair( y, x ), make_pair( yy, xx ) ) );
		a[y][x]--;
		a[yy][xx]++;
		next_c( y, x );
	}
	int cnt = v.size();

	cout << cnt << endl;
	for( int i = 0; i < cnt; i++ ) {
		PP pp = v[i];
		int y = pp.first.first;
		int x = pp.first.second;
		int yy = pp.second.first;
		int xx = pp.second.second;
		cout << y + 1 << " " << x + 1 << " " << yy + 1 << " " << xx + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 5104
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define all(c) (c).begin(), (c).end()

using namespace std;
template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

int main() {
	bool keys[(int)'z'+1];
	rep(i,(int)'z'+1) {
		keys[i] = false;
	}
	keys['y']=true; keys['u']=true; keys['i']=true;
	keys['o']=true; keys['p']=true;
	keys['h']=true; keys['j']=true;
	keys['k']=true; keys['l']=true;
	keys['n']=true; keys['m']=true;

	string a_str;
	bool is_right_back;
	bool is_right;
	bool is_first;
	int cnt;
	while(cin >> a_str) {
		is_first = true;
		cnt = 0;
		if (a_str[0] == '#') { break; }
		rep(i,a_str.size()) {
			if (!is_first) {
				is_right = keys[(int)a_str[i]];
				if (is_right != is_right_back) {
					cnt++;
				}
			}
			is_right_back = keys[(int)a_str[i]];
			is_first = false;
		}
		cout << cnt << endl;
	}

	return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  int answer = n;
  int all_a= 0;
  int min_a = 2000;
  for(int i = 0; i < n; i++){
    int y;
    cin >> y;
    all_a += y;
    min_a = min(y, min_a);
  }
  x -= all_a;
  answer += x / min_a;
  cout << answer << endl;
}


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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

template <ll mod> class modint
{
private:
    ll x;

public:
    modint(ll x = 0) : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) const { return modint(*this) /= rhs; }

    modint operator-() const { return modint(-x); }

    modint pow(ll n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m.x;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<1000000007>;

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

    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    mint dp[n + 1][k + 1] = {};
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        mint sum[k + 2];
        sum[0] = 0;
        for (int j = 0; j <= k; j++) sum[j + 1] = sum[j] + dp[i][j];
        for (int j = 0; j <= k; j++) {
            dp[i + 1][j] = sum[j + 1] - sum[max(0, j - a[i])];
        }
    }

    cout << dp[n][k] << endl;
    return 0;
}

Measured memory_bytes: 80000
import java.util.*;

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

        for (int i1 = 'a'; i1 <= 'z'; i1++) {
            String s1 = String.valueOf((char) i1);
            if (s.contains(s1)) {
                k--;
                if (k == 0) {
                    System.out.println(s1);
                    return;
                }
            } else {
                continue;
            }
            for (int i2 = 'a'; i2 <= 'z'; i2++) {
                String s2 = String.valueOf((char) i2);
                if (s.contains(s1+s2)) {
                    k--;
                    if (k == 0) {
                        System.out.println(s1+s2);
                        return;
                    }
                } else {
                    continue;
                }
                for (int i3 = 'a'; i3 <= 'z'; i3++) {
                    String s3 = String.valueOf((char) i3);
                    if (s.contains(s1+s2+s3)) {
                        k--;
                        if (k == 0) {
                            System.out.println(s1+s2+s3);
                            return;
                        }
                    } else {
                        continue;
                    }
                    for (int i4 = 'a'; i4 <= 'z'; i4++) {
                        String s4 = String.valueOf((char) i4);
                        if (s.contains(s1+s2+s3+s4)) {
                            k--;
                            if (k == 0) {
                                System.out.println(s1+s2+s3+s4);
                                return;
                            }
                        } else {
                            continue;
                        }
                        for (int i5 = 'a'; i5 <= 'z'; i5++) {
                            String s5 = String.valueOf((char) i5);
                            if (s.contains(s1+s2+s3+s4+s5)) {
                                k--;
                                if (k == 0) {
                                    System.out.println(s1+s2+s3+s4+s5);
                                    return;
                                }
                            } else {
                                continue;
                            }

                        }
                    }
                }
            }
        }

        // int[] minc = new int[5];
        // int count = 0;
        // out: for(int i='a'; i<='z'; i++){
        // for(int j=0; j<s.length(); j++){
        // if(s.charAt(j) == i){
        // minc[count] = i;
        // count++;
        // if(count = 5) break out;
        // continue out;
        // }
        // }
        // }

        // if(k == 1){
        // System.out.println((char)minc[0]);
        // }

        // count = 5-k;

        // for(int i=0; i<5; i++){
        // int num = 0;

        // }
    }
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int A = s[0] - '0';
  int B = s[1] - '0';
  int C = s[2] - '0';
  int D = s[3] - '0';
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int v = A;
        if (i) {
          v += B;
        } else {
          v -= B;
        }
        if (j) {
          v += C;
        } else {
          v -= C;
        }
        if (k) {
          v += D;
        } else {
          v -= D;
        }
        if (v == 7) {
          cout << A
               << (i ? '+' : '-')
               << B
               << (j ? '+' : '-')
               << C
               << (k ? '+' : '-')
               << D
               << "=7"
               << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        Long A = scanner.nextLong();
        Long B = scanner.nextLong();
        Long C = scanner.nextLong();
        Long K = scanner.nextLong();
        Long count = 0L;
        if(K >= A){
            K = K - A;
            count += A;
        }else{
            count += K;
            K = 0L;
        }
        K = K - B;
        if(K > 0){
            count = count - K;
        }

        System.out.println(count);
        
	}
}

Measured memory_bytes: 35716
N,M = map(int,input().split())
X = list(map(int,input().split()))
li = [0]*(M-1)
X.sort()
for i in range(M-1):
    li[i] = abs(X[i+1]-X[i])
li.sort()
print(sum(li[:max(0,M-N)]))

Measured memory_bytes: 13968
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<int,int>q;
int main(void)
{
     int i,j,k,n,m,l=0;
     scanf("%d",&n);
     for(i=0;i<n;i++)
     {
          scanf("%d",&k);
          q[k]++;
     }
     scanf("%d",&m);
     for(i=0;i<m;i++)
     {
          scanf("%d",&k);
          if(q[k]==0)
          {
               l=1;
               break;
          }
          else
               q[k]--;
     }
     if(l==0)
          printf("YES\n");
     else
          printf("NO\n");
     return 0;
}


Measured memory_bytes: 9600
//Author- Vaibhav singh
//will be expert soon 
// *#####################################################################################*
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define en "\n"
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define re return 0;
// *#######################################################################################*

/*ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
*/

/*void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 10000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 10000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}  */



// *#########################################################################################*

int main()
{
      fast
 
    
      ll a,b,n;
      cin>>a>>b>>n;
      ll i,mx=0;
      ll x=min(n,b-1);
      ll z=floor((a*x)/b)-a*floor(x/b);
          
          o(z)
          
    
            




re}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
 
 
 
struct node{
  int lc;
  int rc;
  int key;
  void init(int a){
    lc=rc=-1;
    key=a;
  }
};
 
#define bstN 600000
struct bst{
 
  int size;
  node t[bstN];
 
  void init(){
    size=0;
  }
   
  void insert(int v){
    int i=0;
    while(i<size){
      int& child=(v<t[i].key?t[i].lc:t[i].rc);
      if(child==-1)child=size;
      i=child; 
    }
    t[size++].init(v);
  }
 
  void preord(int pos){
    if(pos==-1||pos==size)return;
    preord(t[pos].lc);
    printf(" %d",t[pos].key);
    preord(t[pos].rc);
  }
   
  void inord(int pos){
    if(pos==-1||pos==size)return;
    printf(" %d",t[pos].key);
    inord(t[pos].lc);
    inord(t[pos].rc);
  }
};
 
 
bst T;
 
int main(){
  T.init();
  int n,a;
  char str[100];
  scanf("%d",&n);
   
  while(n--){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&a);
      T.insert(a);
    }else{
      T.preord(0);
      printf("\n");
      T.inord(0);
      printf("\n");
    }
  }
 
  return 0;
}


Measured memory_bytes: 9016
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int k;
    cin >> k;
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
/* ex7_3
   urah  */

#include <stdio.h>
#include <stdlib.h>


int main(void){
    int height, width;
    int *row, *col;
    char **matrix;
 
    // 入力受け取り
    scanf("%d\t%d", &height, &width);
    
    // メモリ領域の確保
    row = (int*)calloc(height, sizeof(int));
    // エラーチェック
    if (row == NULL){
        exit(1);
    }

    // メモリ領域の確保
    col = (int*)calloc(width, sizeof(int));
    // エラーチェック
    if (col == NULL){
        exit(1);
    }
    
    // メモリ領域の確保
    matrix = (char**)calloc(height, sizeof(char*));
    // エラーチェック
    if (matrix == NULL){
        exit(1);
    }
    for (int i=0; i<height; i++){
        // メモリ領域の確保
        matrix[i] = (char*)calloc(width, sizeof(char));
        // エラーチェック
        if(matrix[i] == NULL){
            exit(1);
        }
    }

    // マス目の入力を受け取っていく
    for (int i=0; i < height; i++){
        for (int j=0; j < width; j++){
            scanf(" %c", &matrix[i][j]);
        }
    }
 
    // 黒いマスがある行または列は1にする
    for (int i=0; i < height; i++){
        for (int j=0; j < width; j++){
            if (matrix[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
 
    // 行も列も1であれば出力
    for (int i=0; i < height; i++){
        if (row[i] == 1){
            for (int j=0; j < width; j++){
                if (col[j] == 1){
                    printf("%c", matrix[i][j]);
                }
            }
            printf("\n");
        }
    }
    
    // メモリの解放
    free(row);
    free(col);
    for (int i=0; i<height; i++){
        free(matrix[i]);
    }
    free(matrix);
 
    return 0;
}

Measured memory_bytes: 1624
#include <cstdio>
#include <cstring>

typedef long long ll;

int N;
ll plan[31];

bool can(int maxDay){
    ll x = plan[maxDay];
    
    for(int i=maxDay-1;i>=1;i--){
        bool f = false;
        for(int j=0;j<N;j++){
            if((x >> j & 1) && (plan[i] >> j & 1)){f = true; break;}
        }

        if(!f){continue;}

        x |= plan[i];
    }

    // printf("%d: %lld\n", maxDay, x);
    return __builtin_popcountll(x) == N;
}

int main(){
    while(scanf("%d", &N), N){
        memset(plan, 0ll, sizeof(plan));
        
        for(int i=0;i<N;i++){
            int f;
            scanf("%d", &f);

            for(int j=0;j<f;j++){
                int d;
                scanf("%d", &d);

                plan[d] |= 1ll << i;
            }
        }

        int res = -1;
        for(int i=1;i<=30;i++){
            if(can(i)){res = i; break;}
        }

        printf("%d\n", res);
    }
}

Measured memory_bytes: 1016
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<fstream>
#include <stdio.h>
#include <string.h>
#include<queue>
using namespace std;
 
void winter_is_coming()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL );
}
 
int main()
{
    //freopen(".in", "r", stdin); //fclose (stdout);
	winter_is_coming();
  
	int a,b,d,c;
	cin>>a>>b;
	if(b==100) d=1000;
	else if(b>9) d=100;
	else         d=10;
	a=a*d+b;
	//cout<<a;
	c=sqrt(double(a));
	if(sqrt(double(a))-c==0)
		cout<<"Yes\n";
	else
		cout<<"No\n";
 
   // system("pause");
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
	ull n, m;
	cin >> n >> m;
	VEC(ll, 10, a, -1); 
	ll b[10] = { 0,2,5,5,4,5,6,3,7,6 };
	REP(i,m) 
	{
		ll c;
		cin >> c;
		a[c] = b[c];
	}
	VEC(ll, n + 1, dp, -1);
	dp[0] = 0;

	REP( i, n + 1 )
	{
		if( i <= 1 ) continue;
		REP( j, 10 )
		{
			if( a[j] < 0 ) continue;
			if( i - a[j] < 0 ) continue;
			else
			{
				dp[i] = max( dp[i], dp[i-a[j]] + 1 );
			}
		}
	}

	ll maxK = dp[n];
	string s;
	ll rest = n;
	REP( k, maxK )
	{
		BREP( i, 10 )
		{
			if( i == 0 ) continue;
			if( a[i] < 0 ) continue;
			if( rest < b[i] ) continue;
			if( dp[rest - b[i]] == dp[rest] - 1 )
			{
				s += i + '0';
				rest -= b[i];
				break;
			}
		}
	}
	
	cout << s << endl;
	return 0;
}

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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = 998244353;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 1e5 + 5;

int D[N], CNT[N];

int Power(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;
}

int main() {
 
	sync;
	
	int n, ans = 1, cnt = 0; cin >> n;
	for (int i = 1; i <= n; i++) cin >> D[i], CNT[D[i]]++, cnt += (D[i] == 0);
	if (D[1] != 0 || cnt > 1) die(0);
	for (int i = 1; i <= n - 1; i++) {
		if (CNT[i] == 0) continue;
		if (CNT[i - 1] == 0) die(0);
		ans = 1LL * ans * Power(CNT[i - 1], CNT[i]) % MOD;
	}
	cout << ans << endl;
		
	return 0;
}


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

using ll = long long;

std::unordered_map<ll, int> map;

int n;

ll ans, s;

int main(){
	scanf("%d", &n);
	map[0] = 1;
	for(int i=1,a;i<=n;++i){
		scanf("%d", &a);
		s += a;
		ans += map[s];
		++ map[s];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8520
n = int(input())
d = dict()
res = 0
for _ in range(n):
    s = input()
    s = list(s)
    s.sort()
    s = "".join(s)
    if s in d:
        res += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(res)

Measured memory_bytes: 17808
def main():
    def pearser(s, n):
        if s == "":
            return ""
        i = 0
        while 1:
            if not s[i].isdigit():break
            i += 1
        if i == 0:
            r = pearser(s[i + 1:], n - 1)
            return s[0] + r
        if s[i] == "(":
            r = Parentp(s[i:], n, int(s[:i]))
        else:
            r = s[i] * int(s[:i])
            if len(r) >= n:
                return r[:n]
            r += pearser(s[i+1:], n - len(r))
        return r

    def Parentp(s, n, p):
        if s == "": return ""
        b = 0
        c = 0
        i = 0
        while 1:
            if s[i] == "(":
                c += 1
            if s[i] == ")":
                c -= 1
            if c == 0:
                break
            i += 1
        r = pearser(s[b + 1:i], n)
        l = len(r)
        if l * p >= n:
            r = r * (n // l + 1)
            return r[:n]
        r = r * p
        r += pearser(s[i+1:], n - len(r))
        return r

    def m(s,n):
        n = int(n)
        r = pearser(s, n + 1)
        if len(r) <= n:
            print(0)
            return
        print(r[n])

    while 1:
        s, n = map(str, input().split())
        if s == n == "0":
            break
        m(s, n)

main()


Measured memory_bytes: 9800
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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


    int N, K;
    cin >> N >> K;

    vector<int> P(N), C(N);
    REPinit(i, 0, N) {
        cin >> P[i];
        P[i]--;
    }

    REPinit(i, 0, N) {
        cin >> C[i];
    }

    ll ans = -1 * (ll)1e18;

    REPinit(i, 0, N) {
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while (true)
        {
            cycle_cnt++;
            cycle_sum += C[v];
            v = P[v];
            if (v == i) break;
        }

        ll path = 0;
        int cnt = 0;

        while (true)
        {
            cnt++;
            path += C[v];

            if (cnt > K) break;

            int num = (K - cnt) / cycle_cnt;
            ll score = path + max((ll)0, cycle_sum) * num;
            if (ans < score) ans = score;

            v = P[v];
            if (v == i) break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(){
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int count = 0;

  for(int i=0; i<=N; i++){
    for(int j=0; j<=N; j++){
      if((N - (R*i + G*j)) %B == 0){
        if((N - (R*i + G*j)) >= 0){
        count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
n, y = gets.split.map(&:to_i)

_i, _j, _k = -1,-1,-1


(0..n).each do |i|
  (0..n-i).each do |j|
    if i*10000 + j* 5000+ (n-i-j) *1000 == y
      _i, _j,_k=i,j,n-i-j
    end
  end
end

puts "#{_i} #{_j} #{_k}"

Measured memory_bytes: 1916
from collections import defaultdict
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M, K = map(int, input().split())
    fd = defaultdict(list)
    uf = UnionFind(N+1)
    for _ in range(M):
        a, b = map(int, input().split())
        if a in fd:
            fd[a].append(b)
        else:
            fd[a] = [b]
        if b in fd:
            fd[b].append(a)
        else:
            fd[b] = [a]
        uf.union(a,b)
    for _ in range(K):
        c, d = map(int, input().split())
        if uf.same(c, d):
            fd[c].append(d)
            fd[d].append(c)
    r = []
    for i in range(1, N+1):
        r.append(uf.size(i)-len(fd[i])-1)
    print(' '.join(str(i) for i in r))
main()


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

int main(){

    string result;
    char C[3][3];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> C[i][j];
        }
    }

    cout << C[0][0]<<C[1][1]<<C[2][2]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    cout << s.substr(0, 4) + " " + s.substr(4) << endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());

        long resultA = a - k;
        long resultB = b;
        if (resultA < 0) {
            resultB = Math.max(b + resultA, 0);
            resultA = 0;
        }

        System.out.println(resultA + " " + resultB);

        sc.close();
    }
}


Measured memory_bytes: 21844
def main():
    n, a, b, c, d = map(int, input().split())
    last = abs(a-b)
    if (n-1)*d < last:
        print("NO")
    else:
        f = False
        for i in range(n):
            p = d*i
            q = (n-1 - i)//2 * (d-c)
            if (n-1 - i) % 2 == 1:
                if q < c:
                    if p + c - q <= last <= p + d + q:
                        f = True
                    if p - d - q <= last <= p - c + q:
                        f = True
                else:
                    if p - d - q <= last <= p + d + q:
                        f = True
            else:
                if p - q <= last <= p + q:
                    f = True
        for i in range(n):
            p = c*i
            q = (n-1 - i)//2 * (d-c)
            if (n-1 - i) % 2 == 1:
                if q < c:
                    if p + c - q <= last <= p + d + q:
                        f = True
                    if p - d - q <= last <= p - c + q:
                        f = True
                else:
                    if p - d - q <= last <= p + d + q:
                        f = True
            else:
                if p - q <= last <= p + q:
                    f = True
        if f:
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9268
#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 n;
  cin >> n;
  vector<vector<int>> evid(n, vector<int>(n, -1));//-1:証言無し 1:正直　2:不親切
  rep(i, n)
  {
    int a;
    cin >> a;
    rep(j, a)
    {
      int x, y;
      cin >> x >> y;
      x--;
      evid[i][x] = y;
    }
  }
  int ans = 0;
  rep(i, 1<<n)
  {
    bool chk = true;
    rep(j, n)
    {
      if ((i & 1<<j) == 0)
        continue;
      rep(k, n)
      {
        if (evid[j][k] == -1)
          continue;
        if ((i>>k & 1) != evid[j][k])
          chk = false;
      }
    }
    if (chk)
      ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int H,N;
    cin>>H>>N;
    vector<pair<int,int>> magic(N);
    REP(i,N) cin>>magic[i].first>>magic[i].second;
    using P = pair<int,int>;
    int ans=1e9;
    vector<vector<int>> dp(N+1,vector<int>(10*H,1e9));
    dp[0][0]=0;
    REP(i,N) REP(j,10*H){
        dp[i+1][j]=dp[i][j];
        if(j-magic[i].first>=0) dp[i+1][j]=min(dp[i+1][j],dp[i+1][j-magic[i].first]+magic[i].second);
    }
    rep(i,H,10*H) ans=min(ans,dp[N][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 393088
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())

for i in range(N):
    B = int(input())
    for c in range(3):
        for r in range(3):
            if A[c][r] == B:
                A[c][r] = 0

R = [0, 0, 0]
C = [0, 0, 0]
S = [0, 0]

for i in range(3):
    for j in range(3):
        R[i] += A[i][j]
        C[j] += A[i][j]

for i in range(3):
    S[0] += A[i][i]
    S[1] += A[i][2 - i]

print('Yes' if 0 in R + C + S else 'No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>

int main() {
	int n, a[7] = { 1,2,4,8,16,32,64 }, ans=0;
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 7; ++j) {
			if (a[j] == i && ans < i) { ans = i; }
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int s(int n) {
    return ceil((double)n / 10) * 10;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    int sum = s(a) + s(b) + s(c) + s(d) + s(e);
    //cout << sum << endl;
    sum -= max({s(a) - a, s(b) - b, s(c) - c, s(d) - d, s(e) - e});
    cout << sum << endl;
    
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		//底辺a
		double a = sc.nextDouble();

		//斜辺b
		double b = sc.nextDouble();

		//角度C
		double C = sc.nextDouble();

		//高さh
		double h;

		//高さ
		//absinC/2÷a/2=bsinC
		double C2 = Math.toRadians(C);
		h = b * (Math.sin(C2));

		//面積S
		double S;
		S = (a * h) / 2;

		//周の長さL
		double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.toRadians(C)));
		double L = a + b + c;

		System.out.println(S);
		System.out.println(L);
		System.out.println(h);

		sc.close();
	}

}



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

int gcd(int i, int j){
  if(i<j) swap(i,j);
  while(j!=0){
    int m = i % j;
    i = j;
    j = m;
  }
  return i;
}

int main(){
  int n;
  cin >> n;
  long long int ans=0;
  for(int i=1; i<=n; i++){
    for(int j=i; j<=n; j++){
      for(int k=j; k<=n; k++){
        if(i==j&&j==k) ans += gcd(gcd(i,j),k);
        else if(i==j||j==k) ans += 3*gcd(gcd(i,j),k);
        else ans += 6*gcd(gcd(i,j),k);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll d,n;cin>>d>>n;
  if(n==100)n++;
  ll x=pow(100,d);
  cout<<x*n<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define rep(i,n) for(int i=0;i<(n);i++)
    #define loop(i,x,n) for(int i=(x);i<(n);i++)
    #define all(x) (x).begin(),(x).end()
    #define pb push_back
    #define mp make_pair
    #define fir first
    #define sec second
    #define ub upper_bound
    #define lb lower_bound
    #define int long long
    using namespace std;
    const int MOD=1000000007;
    const int INF=1000000009;
     
     
     
    signed main(){
      int n;
      cin>>n;
      int odd=1;
      rep(i,n){
        int a;
        cin>>a;
        if(a%2==0)odd*=2;
      }
      cout<<pow(3,n)-odd<<endl;
      return 0;
    }

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
long long const INF = 1001001001001001;

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

ll n,s;
cin >> n >> s;

// f(p, c) := cをp進法表示したときの各桁の和
auto f = [&](int p, ll c) {
    ll d,res = 0;
    while(c) {
        d = c % p;
        res += d;
        c /= p;
    }
    return res;
};

ll r = floor(sqrt(n));
for(int b = 2; b <= r; ++b) {
    if( f(b, n) == s ) {
        cout << b << endl;
        return 0;
    }
}

// 以下は存在するならば b > r が成立する
// このときnはb進法表示で高々2桁で表される
// n = x1 * b + x0　かつ x1 + x0 = s を満たすb,x0,x1を探せばいい
// これは x1 <= r であることを利用して全探索できる

ll b = INF;
if( n == s ) chmin(b, n+1);

for(int x1 = 1; x1 <= r; ++x1) {
    if(x1 > s) continue;
    ll x0 = s - x1;
    if( (n - x0) % x1 == 0 ) {
        ll pb = (n - x0) / x1;
        if(pb > x1 && pb > x0) chmin(b, pb);
    }
}

if(b == INF) cout << -1 << endl;
else cout << b << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n, a, b;
  cin>>n>>a>>b;
  vl p(n);
  ll que1 = 0;
  ll que2 = 0;
  ll que3 = 0;
  rep(i,n){
    cin >> p[i];
    if (p[i] <= a){
      que1++;
    }
    else if(p[i]<=b){
      que2++;
    }
    else{
      que3++;
    }
  }
  ll ans = min(que1, min(que2, que3));
  print(ans);
}

Measured memory_bytes: 3556
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

int main(){
	int a,b;cin>>a>>b;
	int ans=max(a+b,a-b);
	chmax(ans,a*b);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
const fs = require('fs');

const main = (input) => {
  const tail = input.slice(1).map(x => x.split(' '));

  const money = tail.map(x => conv(Number(x[0]), x[1])).reduce((acc, x) => acc + x, 0);

  console.log(money);
};

const conv = (n, type) => {
  if (type === 'JPY') {
    return n;
  } else if (type === 'BTC') {
    return n * 380000.0;
  }
};

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


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  string s,t;cin >> s >> t;
  rep(i,N){
    if(s.substr(i,N-i) == t.substr(0,N-i)){
      cout << N+i << endl;
      return 0;
    }
  }
  cout << 2*N << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	char a,b,c;
	int ans1=0,ans2=0,ans3=0;
	cin>>a>>b>>c;
	if ((a=='a')||(b=='a')||(c=='a')) ++ans1;
	if ((a=='b')||(b=='b')||(c=='b')) ++ans2;
	if ((a=='c')||(b=='c')||(c=='c')) ++ans3;
	if ((ans1)&&(ans2)&&(ans3)) 
	    cout<<"Yes"<<endl;
	    else
	    cout<<"No"<<endl;
}

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

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

    int a[N] = {0};
    bool updated[N] = {false};
    if (1 < N) {
        a[0] = 1;
    }

    for (int m=0;m<M;m++) {
        int s, c;
        cin >> s >> c;
        int idx = s - 1;
        int idx_n = a[idx];
        bool up = updated[idx];
        if (up) {
            if (idx_n != c) {
                cout << "-1" << endl;
                return 0;
            }
        } else {
            a[idx] = c;
            updated[idx] = true;
        }
    }
    if (1 < N && a[0] == 0) {
        cout << "-1" << endl;
    } else {
        for (int i=0;i<N;i++) {
            cout << a[i];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string a,b,c;
	cin >> a >> b >> c;
	if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

int main(void)
{
    string S;
    cin >> S;

    string s = S;
    reverse(s.begin(), s.end());

    int ans = 0;
    for (int i = 0; i < (int)S.size() / 2; i++) {
        if (S[i] != s[i])
            ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        long days = 500000000000000L;
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        long temp = 0;

        for (int i = 0; i<S.length(); i++) {
            long target = S.charAt(i) - '0';
            //System.out.println(target);

            temp += Math.pow(target, days);

            if (temp >= K) {
                System.out.println(target);
              	return;
            }
        }
    }
}


Measured memory_bytes: 23764
import java.util.*;
public class Main{
	static int n;
	static int m;
	static int[][] table = new int[9][9];
	static int ans;
	static boolean check(int team){
		int win = 0;
		int lose = 0;
		for(int i=0; i<n; i++){
			if(table[team][i]>0)win++;
			else if(table[team][i]<0)lose++;
		}
		return win <= (n-1)/2 & lose <= (n-1)/2;
	}

	static void dfs(int cnt){
		if(cnt==n*n){
			ans++;
			return;
		}
		int team = cnt / n;
		int against = cnt % n;
		if(table[team][against]==2 || table[team][against]==-2 || team>=against){
			if(check(team))dfs(cnt+1);
			return;
		}
		
			table[team][against] = 1;
			table[against][team] = -1;
			if(check(team))dfs(cnt+1);
	
			table[team][against] = -1;
			table[against][team] = 1;
			if(check(team))dfs(cnt+1);

			table[team][against] = 0;
			table[against][team] = 0;
			return;
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		while(n!=0){
			m = sc.nextInt();
			for(int i=0; i<9; i++){
				Arrays.fill(table[i], 0);
			}
			for(int i=0; i<m; i++){
				int x = sc.nextInt()-1;
				int y = sc.nextInt()-1;
				table[x][y] = 2;
				table[y][x] = -2;
			}
			ans = 0;
			dfs(0);
			System.out.println(ans);
			n = sc.nextInt();
		}
	}
}


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

int main() {
  int N, tmp;
  cin >> N;
  
  int sum = 0;
  tmp = N;
  while (tmp > 0) {
    sum += tmp % 10 ;
    tmp /= 10;
  }//while
  
  if( N % sum == 0){
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

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

int main(){
    int S;
    cin>>S;
    
    int L=S/100,R=S%100;
    if(1<=L&&L<=12){
        if(1<=R&&R<=12) cout<<"AMBIGUOUS"<<endl;
        else cout<<"MMYY"<<endl;
    }else{
        if(1<=R&&R<=12) cout<<"YYMM"<<endl;
        else cout<<"NA"<<endl;
    }
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll as(n);
  rep(i, n) cin >> as[i];

  vvll dp(n, vll(n, INF));
  vll csum(n + 1, 0);
  rep(i, n) {
    dp[i][i] = 0;
    csum[i + 1] = as[i] + csum[i];
  }

  repLRE(h, 2, n) {
    rep(l, n) {
      ll r = l + h - 1;
      if (r >= n) break;
      repLRE(k, l, r - 1) chmin(dp[l][r], dp[l][k] + dp[k + 1][r] + csum[r+1] - csum[l]);
    }
  }

  cout << dp[0][n-1] << endl;

  return 0;
}


Measured memory_bytes: 1536
import java.util.*;

//update 2020/1/1 23:01

public class Main{

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

  public static void main(String[] args) {

    String inn = sc.next();

    char[] in = inn.toCharArray();

    char out = in[0]++;




    System.out.println(in[0]);

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

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

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

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

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

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

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

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

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

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

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

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

}


Measured memory_bytes: 21588