akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, k int
	var s string

	fmt.Scanf("%d %d\n%s", &n, &k, &s)
	fmt.Println(logic(k, s))
}

func logic(k int, s string) string {
	var result string
	for i, c := range s {
		if i == k-1 {
			result += strings.ToLower(string(c))
		} else {
			result += string(c)
		}
	}

	return result
}


Measured memory_bytes: 640
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n,m; cin >> n >> m;
  vector<int> a(n,1);
  vector<bool> in_red(n,false);
  in_red[0] = true;
  
  rep(i,m){
    int x,y; cin >> x >> y;
    x--;y--;
    a[x]--; a[y]++; //xからとってyに動かす
    if(in_red[x]){//もし赤が入っている可能性があったら
      in_red[y] = true; //yには赤が入っている可能性がある
      if(a[x] == 0){ //動かした後にボールの数が0になっていたら
        in_red[x] = false; //xには絶対赤はいない
      } 
    }
  }
  
  int cnt = 0;
  rep(i,n) if(in_red[i]) cnt++;
  
  cout << cnt << endl;
  
  
  return 0;
}

Measured memory_bytes: 640
n = int(input().rstrip())
member_str_list = input().rstrip().split(' ')
member_list = []

for member in member_str_list:
    member_list.append(int(member))

step_list = [0]
for i in range(len(member_list)):
    if i - 1 >= 0:
        front_member = member_list[i-1] + step_list[i-1]
        current_member = member_list[i]
        if front_member > current_member:
            step_list.append(front_member - current_member)
        else:
            step_list.append(0)

print(sum(step_list))


Measured memory_bytes: 40132
//
//  main.cpp
//  atCoderScript
//
//  Created by 数理科学部 on 2016/08/07.
//  Copyright © 2016年 数理科学部. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void)
{
    vector<string> vec;
    int nm,lngth;
    
    cin >> nm >> lngth;
    
    for(int i = 0;i < nm;i++)
    {
        string t_str;
        cin >> t_str;
        vec.push_back(t_str);
    }
    
    sort(vec.begin(),vec.end());
    for(string x:vec)
    {
        cout << x;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    string a,b;
    cin>>a>>b;
    if(a.length()>b.length())
      cout<<"GREATER"<<endl;
    else if(a.length()<b.length())
      cout<<"LESS"<<endl;
    else {
      ll f=0,g=0;
      for(int i=0;i<a.length();i++)
      {
        if(a[i]-'0'>b[i]-'0')
        {
          f=1;
          break;
        }
        if(a[i]-'0'<b[i]-'0')
        {
          g=1;
          break;
        }

      }
        if(f)
        {
          cout<<"GREATER"<<endl;
        }
        else if(g)
        {
             cout<<"LESS"<<endl;
        }
        else{

           cout<<"EQUAL"<<endl;

    }
}}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    string n;
    cin >> n;
    int res = count(n.begin(), n.end(), '2');
    cout << res << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    //cout<<"hoge";
    int ans=(n*(n-1))/2+(m*(m-1))/2;
    //cout<<(n*(n-1))/2<<" "<<(m*(m-1))/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin>>a>>b;
	if(a<b) cout<<"a < b\n";
	else if(a>b) cout<<"a > b\n";
	else cout<<"a == b\n";
	return 0;
}



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

int A[100][100]={0};
int S[101][101]={0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    
    Fill(A,0);
    Fill(S,0);
    int n;
    cin>>n;

    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){

            cin>>A[i][j];
        
        }
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
    
            int sum=0;
    
            for(int k=0;k<=i;++k){
                for(int l=0;l<=j;++l){
    
                    sum+=A[k][l];
    
                }
            }
    
            S[i+1][j+1]=sum;
            //cout<<sum<<" "; //for debug
    
        }
    }

    int maxsum=A[0][0];

    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            for(int k=i+1;k<n+1;++k){
                for(int l=j+1;l<n+1;++l){
    
                    int partsum=S[k][l]-S[k][j]-S[i][l]+S[i][j];
                    maxsum=(partsum>maxsum?partsum:maxsum);
    
                }
            }
        }
    }

    cout<<maxsum<<"\n";

}

Measured memory_bytes: 3176
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            double[] list = new double[6];
            for (int j = 0; j < 6; j++) {
                list[j] = sc.nextDouble();
            }
            double y = (list[0] * list[5] - list[3] * list[2]) / (list[0] * list[4] - list[3] * list[1]);
            double x = (list[2] - list[1] * y) / list[0];
            System.out.printf("%.3f %.3f\n", x, y);
        }
        sc.close();
    }
}


Measured memory_bytes: 28460
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int check(int n, vector<int> &v){
    while(n > 0){
        int mod = n % 10;
        for(int i = 0; i < v.size(); i++ ){
            if(v[i] == mod ) return 0;
        }
        n = n / 10;
    }
    return 1;
}

int main(){

    int n, k;
    cin >> n >> k;

    vector<int> v(k);
    for(int i = 0; i < k; i++){
        cin >> v[i];
    }


    for(int i = n; i < 1000000; i++){
        if( check(i, v) ){
            cout << i << endl;
            return 0;
        }
    }


}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long int llint;
typedef unsigned long long int ullint;

template<typename T>
auto gcd(T a, T b) {
    T tmp;
    while (b > 0) {
        tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

template<typename T>
auto lcm(T a, T b) {
    return a*b/gcd<T>(a,b);
}

int main(void)
{
    ullint A,B,C,D;
    cin >> A >> B >> C >> D;

    auto CDlcm = lcm<ullint>(C,D);
    auto NA = (A-1) - (A-1)/C - (A-1)/D + (A-1)/CDlcm;
    auto NB = B - B/C - B/D + B/CDlcm;

    cout << NB-NA << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ull unsigned long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define mod (1000*1000*1000+7)
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
template <typename T>
string NumberToString(T pNumber)
{
     ostringstream oOStrStream;
     oOStrStream << pNumber;
     return oOStrStream.str();
}
ll StringToNumber(string s)
{
    stringstream geek(s);
    ll x=0;
    geek>>x;
    return x;
}
ll modPow(ll x,ll n,ll m)
{
    if(n==0)
    return 1%m;
    ull u = modPow(x,n/2,m);
    u=u*u%m;
    if(n%2==1)
    u=u*x%m;
    return u;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
ll seive[1000000];
void seiveForm()
{
    ll i,j;
    seive[0]=seive[1]=1;
    f(i,2,100000)
    {
        if(seive[i]==0)
            for(j=i*i;j<1000000;j+=i)
                seive[j]=1;
    }
}
bool isPerfectSquare(ll num)
{
    double n = sqrt(num);
    return n==(ll)n?true:false;
}
ll countSetbits(ll num)
{
    ull temp=0;
    while(num){
        num=num&(num-1);
        temp++;
    }
    return temp;
}
bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;
   return (ceil(log2(n)) == floor(log2(n)));
}
ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a;
    cin>>a;
    cout<<(modPow(a,1,mod)+modPow(a,2,mod)+modPow(a,3,mod))<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
    ll N,K;

    ll A[51];
    ll ans=0;


int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>K;
    N=50;
    ll temp=K-N*(K/N);
    DEB(temp)DEB(K)DEB(K/N)DEB(N)END
    REP(i,N){
        A[i]=N-1+K/N;
        if(0<temp){
            A[i]+=50-K%N+1;
            temp--;
        }else{
            A[i]-=K%N;
        }
    }
    cout<<50<<endl;
    REP(i,N){
        cout<<A[i];
        if(i!=N-1)cout<<" ";
    }
    return 0;
}

//ARC 079 D - Decrease (Contestant ver.)


Measured memory_bytes: 256
#include<stdio.h>
main()
{
  int h,w;
  int i,j;
  while(1)
    {
      scanf("%d %d",&h,&w);
      if(h==0 && w==0)break;
      for(i=0;i<h;i++)
	{
	  for(j=0;j<w;j++)
	    {
	      if(i==0 || i==h-1 || j==0 || j==w-1)
		{
		  printf("#");
		}
	      else
		{
		  printf(".");
		}
	    }
	  printf("\n");
	}
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
int main()
{
	int s;
	int i,j,x[4001]={0};
	scanf("%d",&s);
	x[0]=1;
	for(i=0;i<s;i++){
		if(x[i]!=0){
			for(j=3;j<=s;j++){
				if(i+j<=s){
					x[i+j]=x[i]+x[i+j];
					x[i+j]%=1000000007;
				}
			}
		}
	}
	printf("%d\n",x[s]);
	return 0;
}

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


int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	rep(i,n) cin >> a[i+1];
	vector<int> memo(n+1,0);
	int t;
	for(int i(n);i>=1;--i){
		t = a[i];
		if(i<=n/2){
			for(int j(i*2);j<=n;j+=i){
				t = (t + memo[j])%2;
			}
		}
		memo[i] = t;
	}
	vector<int> ans;
	rep(i,n){
		if(memo[i+1] == 1){
			ans.push_back(i+1);
		}
	}
	cout << ans.size() << endl;
	rep(i,ans.size()) cout << ans[i] << ' ' << endl;
	return 0;
}

Measured memory_bytes: 3192
import collections

N, K, Q = map(int,input().split())
A = []
for i in range(Q):
    A.append(int(input()))

c = collections.Counter(A)
cnt = [0] * N
for i in c.most_common():
    cnt[i[0]-1] = i[1]

if K > Q:
    for i in range(N):
        print('Yes')
elif K <= Q:
    for i in cnt:
        if i >= Q-K+1:
            print('Yes')
        else:
            print('No')

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

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

    if (a + b == 3)
    {
        cout << 3 << endl;
        exit(0);
    }

    if (a + b == 4)
    {
        cout << 2 << endl;
        exit(0);
    }

    cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
int a[105][105];
 
int main() {
	memset(a, 0, sizeof(a));
	int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x = 1, y = 1;
    for(int i = 1; i <= k; i ++) {
    	int cnt = 0;
        scanf("%d", &cnt);
        while(cnt --) {
			a[x][y] = i;
			if(y == m && (x & 1)) y = m, x ++;
			else if(y == 1 && !(x % 2)) y = 1, x ++;
			else if(x & 1) y ++;
			else y --;
        }
    }
    for(int i = 1; i <= n; i ++)
   		for(int j = 1; j <= m; j ++)
        printf("%d%c", a[i][j], j == m ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 384
//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int_least64_t INF = 10000000;

int main(){
    //cin coutを高速化
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

    int a, b, c;
    cin >> a >> b >> c;
    string res = "No";

    if (a == b)
        if (a != c)
            res = "Yes";
    if (b == c)
        if(b != a)
            res = "Yes";
    if (a == c)
        if(a != b)
            res = "Yes";

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define zeros(x) ((x) & (-x))
#define inf 1e18

using namespace std;

typedef long long ll;
typedef long double ld;

ll n;
string s, t;

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    cin>>s>>t;
    for (int i=0; i<s.size(); i++)
        cout<<s[i]<<t[i];

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
using namespace std;
typedef long long ll;
ll N, M;
vector<int> G[100005];
int color[100005];

bool dfs(int v, int c){
  color[v] = c; //頂点vをcで塗る
  rep(i, G[v].size()){
    //隣接している頂点が同じ色ならfalse
    if(color[G[v][i]]==c) return false;
    //隣接している頂点がまだ塗られていないのなら-cで塗る
    if(color[G[v][i]]==0 && !dfs(G[v][i], -c)) return false;
  }
  //全ての頂点が塗れたらtrue
  return true;
}

bool is_bigraph(){
  rep(i, N){
    if(color[i]==0){
      //まだ頂点iが塗られていないなら1で塗る
      if (!dfs(i, 1)){
        return false;
      }
    }
  }
  return true;
}

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

  cin >> N >> M;
  int a, b;
  rep(i, M){
    cin >> a >> b;
    G[a-1].push_back(b-1); //indexのため-1
    G[b-1].push_back(a-1); //同様
  };
  ll ans;
  if(!is_bigraph()){
    ans = (N*(N-1))/2 - M;
    cout << ans << endl;
    return 0;
  }

  ll b_cnt=0;
  ll w_cnt=0;
  rep(i, N){
    if (color[i]>0) b_cnt++;
    else w_cnt++;
  }
  ans = b_cnt*w_cnt - M;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n;
    cin >> n;
    map<int, int> m;
    ll sm = 0;
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        m[x]++;
        sm += x;
    }

    int q;
    cin >> q;
    for (int i=0; i<q; i++) {
        int x, y;
        cin >> x >> y;
        sm += ll(m[x])*(y-x);
        m[y] += m[x];
        m[x] = 0;
        cout << sm << "\n";
    }
}


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

int main() {
    int N, K;
    cin >> N >> K;
    double ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += pow(0.5, ceil(max(0.0, log2(1.0 * K / i)))) / N;
    }
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}


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

int people[4][3][10];
int N,b,f,r,v;
int main() {
	cin >> N;
	for(int i=0; i<N; ++i) {
		cin >> b >> f >> r >> v;
		people[b-1][f-1][r-1] += v;
	}
	for(int i=0; i<4; ++i) {
		for(int k=0; k<3; ++k) {
			for(int l=0; l<10; ++l) {
				cout << " " << people[i][k][l];
			}
			cout << endl;
		}
		if(i<3) {
			for(int m=0; m<20; ++m) {cout << "#";}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1160
n = int(input())
boxes = [0] * n
amari = list(map(lambda x: int(x), input().split()))


# boxes の うち c の倍数の要素を足し合わせて2で割った余りを返す
def box_count(boxes, c):
    counter = 0
    for i in range(0, len(boxes), c):
        if i + c - 1 < len(boxes):
            counter += boxes[i + c - 1]
    return counter % 2
        

ballbox = ''   
# 後ろから決めていく
for i in range(n):
    if box_count(boxes, n - i) == 1:
        boxes[n - i - 1] = 1 - amari[n - i - 1]
    else:
        boxes[n - i - 1] = 0 + amari[n - i - 1]

    if boxes[n - i - 1] == 1:
        ballbox += str(n - i) + ' '

print(sum(boxes))
print(ballbox)


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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N, W;
    ist >> N >> W;

    vector<int> w;
    vector<int> v;

    for (int i = 0; i < N; i++)
    {
        int input_w, input_v;
        ist >> input_w >> input_v;
        w.emplace_back(input_w);
        v.emplace_back(input_v);
    }

    /* ------- 計算 ------- */

    vector<vector<long long>> dp_table;

    dp_table.emplace_back(0);
    for (int w_i = 0; w_i <= W; w_i++)
    {
        dp_table.at(0).emplace_back(0);
    }

    for (int i = 0; i < N; i++)
    {
        dp_table.emplace_back(0);
        for (int w_i = 0; w_i <= W; w_i++)
        {
            // i番目の品物を追加できない場合の価値
            long long  insert_value = dp_table.at(i).at(w_i);

            // i番目の品物を追加できる（する）場合の価値
            if (w.at(i) <= w_i)
            {
                insert_value = max(dp_table.at(i).at(w_i - w.at(i)) + v.at(i), insert_value);
            }

            dp_table.at(i + 1).emplace_back(insert_value);
        }
    }

    ost << dp_table.at(N).at(W) << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 83096
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)
void err()
{
    cout<<-1;
    exit(0);
}
int main()
{
    int n,i,j;
    boost;

    string s,t;
    cin>>s>>t;
    n=s.size();
    int arr[n][26];
    rep(i,0,26)arr[n-1][i]=-1;

    for(i=n-2;i>=0;i--)
    {
        rep(j,0,26)
        {
            if(s[i+1]==j+'a')
            {
                arr[i][j]=i+1;
            }
            else arr[i][j]=arr[i+1][j];
        }
    }
    int start[26];
    rep(j,0,26)
    {
        if(s[0]==j+'a')
        {
            start[j]=0;
        }
        else start[j]=arr[0][j];
    }
    int last=start[t[0]-'a'];
    if(last==-1)err();
    ll ans=1;
    rep(i,1,t.size())
    {

        last=arr[last][t[i]-'a'];
        if(last==-1)
        {
            ans++;
            last=start[t[i]-'a'];
            if(last==-1) err();
        }
          
    }
    ll final= s.size()*ans;
    final-= s.size()-last-1;
    cout<<final;



    return 0;
}



Measured memory_bytes: 10704
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    from collections import deque

    # compressed[v]: 縮約後のグラフで縮約前のvが属する頂点
    # num: 縮約後のグラフの頂点数
    def SCC(adj, adj_rev):
        N = len(adj) - 1
        seen = [0] * (N + 1)
        compressed = [0] * (N + 1)
        order = []

        for v0 in range(1, N + 1):
            if seen[v0]:
                continue
            st = deque()
            st.append(v0)
            while st:
                v = st.pop()
                if v < 0:
                    order.append(-v)
                else:
                    if seen[v]:
                        continue
                    seen[v] = 1
                    st.append(-v)
                    for u in adj[v]:
                        st.append(u)

        #print(order)
        seen = [0] * (N + 1)
        num = 0
        for v0 in reversed(order):
            if seen[v0]:
                continue
            num += 1
            st = deque()
            st.append(v0)
            seen[v0] = 1
            compressed[v0] = num
            #print(v0, num)
            while st:
                v = st.pop()
                for u in adj_rev[v]:
                    if seen[u]:
                        continue
                    #print([v, u])
                    seen[u] = 1
                    compressed[u] = num
                    st.append(u)

        return num, compressed

    # 縮約後のグラフを構築
    # 先にSCC()を実行してnum, compressedを作っておく
    def construct(adj, num, compressed):
        N = len(adj) - 1
        adj_compressed = [set() for _ in range(num + 1)]
        for v in range(1, N + 1):
            v_cmp = compressed[v]
            for u in adj[v]:
                u_cmp = compressed[u]
                if v_cmp != u_cmp:
                    adj_compressed[v_cmp].add(u_cmp)
        return adj_compressed

    N, M = map(int, input().split())
    adj = [[] for _ in range(N+1)]
    adj_rev = [[] for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        a += 1
        b += 1
        adj[a].append(b)
        adj_rev[b].append(a)

    NN, compress = SCC(adj, adj_rev)
    ans = []
    Q = int(input())
    query = []
    for _ in range(Q):
        u, v = map(int, input().split())
        query.append((u, v))
        if compress[u+1] == compress[v+1]:
            ans.append(1)
        else:
            ans.append(0)
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()



Measured memory_bytes: 24668
using System;
using System.Linq;

class prog{
  static void Main(){
    
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Console.WriteLine(n[0] + n[1] < 24 ? n[0] + n[1] : n[0] + n[1] - 24);
    
  }
}

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

int main(){
  int h,w;
  cin>>h>>w;
  char c[h][w];
  rep(i,0,h){
    rep(j,0,w){
      cin>>c[i][j];
    }
  }
  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  bool p=true;
  rep(i,0,h){
    rep(j,0,w){
      if(c[i][j]=='#'){
        bool q=false;
        rep(k,0,4){
          if(i+dx[k]>=0 && i+dx[k]<h && j+dy[k]>=0 && j+dy[k]<w){
            if(c[i+dx[k]][j+dy[k]]=='#'){
              q=true;
            }
          }
        }
        if(!q){
          p=false;
        }
      }
    }
  }
  if(p) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define Num 40

int main(void){

    int a[Num], b[Num];
    char t[Num], u[Num];
    int i, j, l, n = 0, c = 1, min, count = 0;
    char s[2], str1[2], str[2];

    scanf("%d", &l); 

    for (i = 0; i <= l-1; i++) {
        scanf(" %c", &t[i]);
        scanf("%d", &a[i]); 
    }

    for (i = 0; i <= l-1; i++) {
        b[i] = a[i];
        u[i] = t[i];
    }

    while (c > 0) {
        c = 0;
        for (i = l-1; i >= 1; i--) {
            if(a[i-1] > a[i]){
                n = a[i-1];
                a[i-1] = a[i];
                a[i] = n;

                s[1] = t[i-1];
                t[i-1] = t[i];
                t[i] = s[1];

                c = 1;
            }
        }
    }
    for (i = 0; i <= l-2; i++) {
        printf("%c", t[i]);
        printf("%d ", a[i]);
    }
    printf("%c", t[i]);
    printf("%d\n", a[i]);
    printf("Stable\n");


    for (i = 0; i <= l-1; i++) {
        min = i;
        for (j = i+1; j <= l-1; j++) {
            if(b[j] < b[min]){
                min = j;
            }
        }
        if(min != i){
            n = b[min];
            b[min] = b[i];
            b[i] = n;

            s[1] = u[min];
            u[min] = u[i];
            u[i] = s[1];
        }
    }

    for (i = 0; i <= l-2; i++) {
        printf("%c", u[i]);
        printf("%d ", b[i]);
    }
    printf("%c", u[i]);
    printf("%d\n", b[i]);
    for (i = 0; i <= l-1; i++) {
        if(t[i] != u[i]){
            count++;
            break;
        }
    }
    if(count != 0){
        printf("Not stable\n");
    }else{
        printf("Stable\n");
    }

    return 0;
}


Measured memory_bytes: 1964
N = int(input())
D12 = [map(int, input().split()) for _ in range(N)]
D1, D2 = [list(i) for i in zip(*D12)]

count = 0
flag = 0
for i in range(N):
  
  if D1[i] == D2[i]:
    count += 1
    if count == 3:
      flag = 1
  else:
    count = 0

if flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

template <typename T>//	Tはintかll
T gcd(T a, T b) {//	最大公約数
	if (a < 0) { a = -a; }
	if (b < 0) { b = -b; }
	if (a == 0) { return b; }
	if (b == 0) { return a; }
	if (a < b) {
		return gcd(a, b % a);
	}
	return gcd(b, a % b);
}

int main() {
	ll N, X, D; cin >> N >> X >> D;

	if (D == 0) {
		if (X == 0) { cout << 1 << endl; }
		else { cout << N + 1 << endl; }
		return 0;
	}

	if (D < 0) {
		D *= -1;
		X *= -1;
	}

	ll G = gcd(abs(X), D);
	ll K = D / G;

	ll sum = 0;
	vector<map<ll, ll>> v;

	for (int i = 0; i <= N; i++) {
		map<ll, ll> mp;
		v.push_back(mp);
	}

	for (ll i = 0; i <= N; i++) {
		ll j = i % K;
		ll y = (i - j) * X / D; // offset

		ll r1 = i * (i - 1) / 2 + y;
		ll r2 = i * (N - 1) - i * (i - 1) / 2 + y + 1;

		if (v[j].find(r1) == v[j].end()) {
			v[j].insert({ r1, 1 });
		}
		else {
			v[j][r1]++;
		}

		if (v[j].find(r2) == v[j].end()) {
			v[j].insert({ r2, -1 });
		}
		else {
			v[j][r2]--;
		}
	}

	for (int i = 0; i <= N; i++) {
		if (i >= K) { break; }
		auto itr = v[i].begin();
		
		ll place = itr->first;
		ll state = itr->second;
		itr++;

		for (; itr != v[i].end(); itr++) {
			if (state > 0) {
				sum += itr->first - place;
			}
			place = itr->first;
			state += itr->second;
		}
	}

	cout << sum << endl;

	return 0;
}

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

#define ll long long int

using namespace std;

int c[3],k;
bool ans;

void check(int n){
    if(n==k){
        if(c[1]>c[0]&&c[2]>c[1]){
            ans=true;
        }
        return;
    }

    for(int i=0;i<3;i++){
        c[i]*=2;
        check(n+1);
        c[i]/=2;
    }


}

int main(){

    cin >> c[0] >> c[1] >> c[2] >> k;

    check(0);

    if(ans){
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    

    
    return 0;
}

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

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

    double prob[N + 1];
    double dp[N + 1][N + 1], res = 0;

    for (int i = 1; i <= N; ++i)
        cin >> prob[i];

    for (int i = 0; i <= N; ++i)
    {
        for (int j = 0; j <= N; ++j)
            dp[i][j] = 0;
    }

    dp[1][0] = 1.0 - prob[1];
    for (int i = 2; i <= N; ++i)
        dp[i][0] = dp[i - 1][0] * (1.0 - prob[i]);


    dp[1][1] = prob[1];
    for (int i = 2; i <= N; ++i)
        dp[i][i] = dp[i - 1][i - 1] * prob[i];

    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j < i; ++j)
            dp[i][j] = dp[i - 1][j] * (1.0 - prob[i]) + dp[i - 1][j - 1] * prob[i];
    }

    for (int i = N / 2 + 1; i <= N; ++i)
        res += dp[N][i];

    cout << fixed << setprecision(10) << res;

    return 0;
}

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

int main() {
  uint32_t A = 0, B = 0;
  std::cin >> A >> B;

  uint32_t first = A / 10000;
  uint32_t second = (A % 10000) / 1000;
  uint32_t third = ((A % 10000) % 1000) / 100;

  uint32_t count = 0;
  for (size_t i = first; i < 10; i++) {
    for (size_t j = second; j < 10; j++) {
      for (size_t k = third; k < 10; k++) {
        uint32_t num = i * 10000 + j * 1000 + k * 100 + j * 10 + i;
        if (num >= A && num <= B) count++;
      }
      third = 0;
    }
    second = 0;
  }

  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 256
//O(NlogN + Qlog^2N)の適当解法(クエリ入れ替えなし)
//意味が分からないバグに悩まされる。→セグメントツリーの子はind*2 + 1とind*2 + 2。間違えてたし気づかなすぎたので、頭ない。
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;

int d;
int x[252521];
int q;
int l[100000], r[100000], e[100000];

const int INF = 1145141919;

const int depth = 17;
class Segtree {
public:
	vector<int> data[1<<(depth+1)];
	
	void ini(int index = 0, int a = 0, int b = (1<<(depth)) - 1) {
		//[a, b]の昇順ソート列をdata[index]に入れる。
		for(int i = a; i <= b; i++ )
			data[index].push_back(x[i]);
		sort(data[index].begin(), data[index].end() );
		if ( b - a > 0 ) {
			ini(index*2 + 1, a, a + (b-a-1)/2);
			ini(index*2 + 2, a + (b-a+1)/2, b);
		}
	}
	
	//[l, r]にv以下の要素がいくつあるか。
	int count(int l, int r, int v, int index = 0, int a = 0, int b = (1<<(depth)) - 1) {
		if ( a > r || b < l || data[index].size() == 0 ) return 0;
		
		if ( l <= a && b <= r ) {			
			//[a, b]の昇順ソート列の中で、v(以下の要素のうち最大の要素)は何番目にある？
			//最初を0番とする。
			int st = -1, ed = data[index].size() - 1, medi;
			while( st <= ed ) {
				medi = (st + ed)/2;
				if ( data[index][medi] > v )
					ed = medi-1;
				else {
					if ( medi+1 == data[index].size() || data[index][medi+1] > v )
						break;
					st = medi+1;
				}
			}
			//Index + 1を返す
			return medi + 1;
		}
		int cnt1 = count(l, r, v, index*2 + 1, a, a + (b-a-1)/2);
		int cnt2 = count(l, r, v, index*2 + 2, a + (b-a+1)/2, b);
		return cnt1 + cnt2;
	}
}seg;

signed main() {
	int i, j;
	cin >> d;
	for( i = 0; i < d; i++ )
		cin >> x[i];
	for( i = d; i < 252521; i++ )
		x[i] = INF;
	
	seg.ini();
	
	cin >> q;
	for( i = 0; i < q; i++ ) {
		cin >> l[i] >> r[i] >> e[i];
		l[i]--; r[i]--;
		int a = max(x[l[i]], x[r[i]]) + e[i];
		int b = min(x[l[i]], x[r[i]]) - e[i];
		
		int cnt1 = seg.count(l[i], r[i], a);
		int cnt2 = seg.count(l[i], r[i], b-1);
		
		int ans = r[i] - l[i] + 1 - (cnt1 - cnt2);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 24628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	int n,ma,mb;
	cin>>n>>ma>>mb;
	vvi med(n,vi(3));
	for(auto&l:med)for(auto&i:l)cin>>i;
	
	int dp[n+1][401][401];
	fill(dp[0][0],dp[n+1][0],10000);
	dp[0][0][0]=0;
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<=10*(i-1);j++){
			for(int k=0;k<=10*(i-1);k++){
				if(dp[i-1][j][k]!=10000){
					dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]);
					dp[i][j+med[i-1][0]][k+med[i-1][1]]=
						min(dp[i][j+med[i-1][0]][k+med[i-1][1]],
							dp[i-1][j][k]+med[i-1][2]);
				}
			}
		}
	}
	int ans=10000;
	for(int i=1;i*max(ma,mb)<401;i++){
		ans=min(ans,dp[n][ma*i][mb*i]);
	}
	cout<<(ans==10000?-1:ans)<<endl;
	
	
	return 0;
}

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

int whether_prime(int x){
  int c=0;
  for (int i=2; i<x; i++){
    if(x % i == 0){
      c++;
      break;
    }
  }
  if (c == 0){
    return 1;//xは素数
  }
  else{
    return 0;//xは素数じゃない
  }
}
    

int main(){
  int X;
  cin >> X;
  
  int ok = 0;
  while (ok == 0){
    if(whether_prime(X) == 1){
      ok ++;
    }
    else{
      X++;
    }
  }
  
  cout << X << endl;
}

    

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

using namespace std;

int ma = -1;
vector< vector<int> > board, cp;

void sol(int a, int b, int dep) {
	//cout << dep << endl;

	if (0 < cp[a + 1][b] && cp[a + 1][b] > dep + 1) {
		cp[a + 1][b] = dep;
		sol(a + 1, b, dep + 1);
	}
	if (0 < cp[a - 1][b] && cp[a - 1][b] > dep + 1) {
		cp[a - 1][b] = dep;
		sol(a - 1, b, dep + 1);
	}
	if (0 < cp[a][b + 1] && cp[a][b + 1] > dep + 1) {
		cp[a][b+1] = dep;
		sol(a, b+1, dep + 1);
	}
	if (0 < cp[a][b - 1] && cp[a][b - 1] > dep + 1) {
		cp[a][b-1] = dep;
		sol(a, b-1, dep + 1);
	}
}

int main(){

	int a, b;
	char tmp;
	vector< vector<int> > board;

	cin >> a >> b;
	a += 2;
	b += 2;

	board.resize(a);
	cp.resize(a);

	for (int i = 0;i<a;i++) board[i].resize(b);
	for (int i = 0;i<a;i++) cp[i].resize(b);

	for (int i = 0;i<a;i++) {
		board[i][0] = -9;
		board[i][b - 1] = -9;
		cp[i][0] = -9;
		cp[i][b - 1] = -9;
	}
	for (int i = 0;i<b;i++) {
		board[0][i] = -9;
		board[a - 1][i] = -9;
		cp[0][i] = -9;
		cp[a - 1][i] = -9;
	}

	for (int i = 1;i<a - 1;i++) {
		for (int j = 1;j<b - 1;j++) {
			//'#='NG, '.'=OK
			cin >> tmp;
			if(tmp=='#') board[i][j]=-9;
			else board[i][j]=1000;
		}
	}

	for (int i = 1;i<a-1;i++) {
		for (int j = 1;j<b-1;j++) {
			if (board[i][j] != 1000) continue;
			for(int k=1;k<a-1;k++) copy(board[k].begin(), board[k].end(), cp[k].begin());
			tmp = 0;
			/*if (board[i+1][j] != 0 && board[i][j + 1] != 0) tmp++;
			if (board[i][j+1] != 0 && board[i - 1][j] != 0) tmp++;
			if (board[i - 1][j] != 0 && board[i][j - 1] != 0) tmp++;
			if (board[i][j-1] != 0 && board[i + 1][j] != 0) tmp++;
			if (tmp == 0) continue;*/

			cp[i][j] = 0;
			sol(i, j, 1);
			for (int k = 1;k < a - 1;k++) {
				for (int l = 1;l < b - 1;l++) {
					ma = max(ma, cp[k][l]);
				}
			}
			//cout << "call" << i << " " << j << " " << k << " " << l << " " << ma << endl;

			/*for (int k = 1;k<a-1;k++) {
				for (int l = 1;l<b-1;l++) {
					cout << cp[k][l] << " ";
				}
				cout << endl;
			}
			cout << endl;*/

		}
	}
	//sol(3, 1, 1, 5, board, 0);
	cout<< ma << endl;


}


Measured memory_bytes: 256
function main(input){
    let lines = input.split("\n");
    let i=0;
    while(lines[i]!=="0 0"){
        let nums = lines[i].split(" ");
        let put="";
        if(parseInt(nums[0])>parseInt(nums[1])){
            put=nums[1]+" "+nums[0];
        }else{
            put=nums[0]+" "+nums[1];
        }
        console.log(put);
        i++;
        
    }
    
    
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 18492
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 10000000
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int res = 0;
		double mi = INF;
		rep(i,n){
			int mem;
			double h,w;
			scanf("%d",&mem);
			scanf("%lf%lf",&h,&w);
			double x = fabs(22.0-(w/(h/100)/(h/100)));
			if(mi > x){
				mi = x;
				res = mem;
			}
			else if(mi == x){
				res = min(res,mem);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <ext/rope>
// using namespace __gnu_pbds; 
// using namespace __gnu_cxx;
// template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
// template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
// template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}


template <typename A>
istream& operator>>(istream& input,vector<A>& x) { for(auto& i:x) input>>i; return input; }
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {  for(auto& i:x) output<<i<<' '; return output; }
template<typename T, typename U> 
istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> 
ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
inline int power(int x, int y, int res = 1) {
    for (; y; y >>= 1, x = 1ll * x * x % mod) {
        if (y & 1) { res = 1ll * res * x % mod; }
    } return res;
}

signed main () {
    io();
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        
        }
    }
    int flag = 0;
    
    for(int k = 0; k < n; ++k) {
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                if(a[i][k] + a[k][j] < a[i][j]) {
                    debug(i, j, k);
                    flag = 1;
                }
  
            }
        }   
    }
    if(flag) {
        cout << "-1";
        return 0;
    }
    ll sum = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            flag = 0;
            for(int k = 0; k < n; ++k) {
                if(i == k || j == k)    continue;
                if(a[i][k] + a[k][j] == a[i][j]) {
                    flag = 1;
                }
  
            }
            debug(flag, i, j, a[i][j]);
            if(flag == 0)
                sum += a[i][j];
        }   
    }
    cout << sum / 2;

}

//asdasdlkjl

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
#include<utility>
 
using namespace std;
 
long long candy_distribution(int n, long long m, std::vector<long long> a) {
  map<long long, long long> mp;
  long long sum = 0;
  mp[0]++;
  for(int i = 0;i < a.size();i++) {
    sum += a[i];
    mp[sum % m]++;
  }
 
  long long ans = 0;
  
  for (auto i=mp.begin(); i !=mp.end();++i) {
    // cout << "key: " << i->first << " value: " << i->second << endl;
    long long size = i->second;
    ans += (size*(size-1))/2;
  }
 
  return ans;
}
 

int main() {
  int n;
  long long m;
  cin >> n;
  cin >> m;
  vector<long long> a;
  for(int i=0;i<n;i++) {
    long long a_i;
    cin >> a_i;
    a.push_back(a_i);
  }
  cout << candy_distribution(n, m, a);
}



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

int main() {
    int a ,b, c;
    cin >> a;
    b = a/(60*60);
    c = (a - b*60*60)/60;
    cout << b << ":" << c << ":" << a - b*60*60 - c*60 << endl;
}


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

using namespace std;

typedef long long ll;

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

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

ll solve(const ll N, const vector<ll> &L) {
    ll count = 0;

    for (int i = N - 1; i >= 0; i--) {
        for (int j = i - 1; j >= 0; j--) {
            ll longest = L[i];
            ll mid = L[j];
            auto it = lower_bound(L.begin(), L.begin() + j, longest - mid + 1);
            count += (L.begin() + j) - it;
        }
    }

    return count;
}

int main(void) {
    ll N;
    cin >> N;

    vector<ll> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L.begin(), L.end());

    cout << solve(N, L) << endl;

    return 0;
}


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

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

    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    
    sort(d.begin(),d.end());

    int ans = 1;
    for (int i = 1; i < n; i++)
    {
        if(d[i - 1] != d[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
t = list(input())
count = 1000
for i in range(n):
         if s[i:] == t[:-i]:
                  count = i
if s == t:
         print(n)
elif count == 1000:
         print(2*n)
else:
         print(n + count)


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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll fac(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll npr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

int main() {
	string s,t; cin >> s >> t;
	cout << t << s << endl;
}

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

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

  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    s.at(i) = tmp;
  }

  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++) {
    string tmp;
    cin >> tmp;
    t.at(i) = tmp;
  }

  int max_count = 0;
  for (int i = 0; i < n; i++) {
    string value = s.at(i);

    int counter = 1;
    for (int j = i + 1; j < n; j++) {
      if (s.at(j) == value)
        counter++;
    }
    for (int j = 0; j < m; j++) {
      if (t.at(j) == value)
        counter--;
    }
    if (max_count < counter)
      max_count = counter;
  }
  cout << max_count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[808][808];
struct st{
  int y,x;
  st(){}
  st(int y,int x):y(y),x(x){}
};
signed main(){
  int h,w,k;
  cin>>h>>w>>k;
  string a[h];
  for(int i=0;i<h;i++) cin>>a[i];
  int sy,sx;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='S') sy=i,sx=j;
    }
  }
  //cout<<sy<<" "<<sx<<endl;
  int ans=800000;
  int ay[]={0,0,1,-1};
  int ax[]={1,-1,0,0};
  //puts("a");
  memset(dp,-1,sizeof(dp));
  //puts("b");
  queue<st> q;
  q.emplace(sy,sx);
  dp[sy][sx]=0;
  while(!q.empty()){
    st p=q.front();q.pop();
    int y=p.y,x=p.x;
    if(y==0||y==h-1||x==0||x==w-1){
      cout<<1<<endl;
      return 0;
    }
    //cout<<y<<" "<<x<<":"<<dp[y][x]<<endl;
    if(dp[y][x]==k) break;
    for(int i=0;i<4;i++){
      int ny=y+ay[i],nx=x+ax[i];
      if(ny<0||ny>=h||nx<0||nx>=w) continue;
      if(a[ny][nx]=='#') continue;
      if(~dp[ny][nx]) continue;
      dp[ny][nx]=dp[y][x]+1;
      q.emplace(ny,nx);
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(dp[i][j]<0||dp[i][j]>k) continue;
      int tmp=(i-1)/k+1;
      tmp=min(tmp,(j-1)/k+1);
      tmp=min(tmp,((h-i)-2)/k+1);
      tmp=min(tmp,((w-j)-2)/k+1);
      ans=min(ans,tmp+1);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

ll solve(vector<ll> b_sum, ll x) {
    ll ok = -1;
    ll ng = b_sum.size();
    while (abs(ng - ok) > 1) {
        ll mid = (ok + ng) / 2;

        if (x >= b_sum[mid]) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n + 1), b(m + 1), b_sum(m + 1, 0);
    ll current_sum = 0, ans = 0;
    rep(i, n) cin >> a[i];
    rep(i, m) {
        cin >> b[i];
        current_sum += b[i];
    }

    // rep(i, b_sum.size()) cout << b_sum[i] << " ";
    // cout << endl;
    ll j = m;
    rep(i, n + 1) {
        while (j > 0 && current_sum > k) {
            j--;
            current_sum -= b[j];
        }

        if (current_sum > k) break;
        ans = max(ans, i + j);
        if (i == n) break;
        current_sum += a[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 8000
#include<stdio.h>

int main()
{
  int i, j, kai;

  j = 1;
  kai = 0;
  
  for(i=1;i<=9;i++)
    {
      kai = i * j;
      printf("%dx%d=%d\n",i,j,kai);
      for(j=2;j<=9;j++)
	{
	  kai = i * j;
	  printf("%dx%d=%d\n",i,j,kai);
	}
      j=1;
    }
  return(0);
}

Measured memory_bytes: 524