akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string s; getline(cin,s);
    for(int i=0; i<s.size();i++){
        if(s[i]=='p'&&i<s.size()-4)
            if(s[i+1]=='e')
                if(s[i+2]=='a')
                    if(s[i+3]=='c')
                        if(s[i+4]=='h'){
                            cout<<"apple";
                            i+=4;
                            if(i==(int)s.size()-1)cout<<endl;
                            continue;
                        }
        if(s[i]=='a'&&i<s.size()-4)
            if(s[i+1]=='p')
                if(s[i+2]=='p')
                    if(s[i+3]=='l')
                        if(s[i+4]=='e'){
                            cout<<"peach";
                            i+=4;
                            if(i==(int)s.size()-1)cout<<endl;
                            continue;
                        }
        cout<<s[i];
        
    }
}

Measured memory_bytes: 2988
#include <cstdio>
#include <cmath>

const double PI = acos(-1);

int main() {
	double a, b, c, x, angle;
	
	scanf("%lf %lf %lf", &a, &b, &c);
	
	c /= a;
	if(c > a * b / 2) {
		// c = a * (b + x) / 2
		// c = ab/2 + a/2x
		// x = (c - ab/2)/(a/2)
		// x = 2c/a - b
		x = 2*c/a - b;
		angle = atan((b - x) / a) * 180 / PI;
	}
	else {
		x = 2 * c / b;
		angle = atan(b / x) * 180 / PI;
	}
	printf("%.12lf\n", angle);
	return 0;
}

Measured memory_bytes: 128
def check(t, s):
	count = 0
	for i in range(len(t)):
		if s[i] != t[i]:
			count += 1
	return count

s = input()
t = input()
ans = 9999999999
for i in range(len(s)-len(t)+1):
	ans = min(ans, check(t, s[i:i+len(t)]))
print(ans)

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

using namespace std;

int main(){

    int N, x = 0, i, maximum;
    string str;

    cin >> N;
    cin >> str;

    maximum = x;

    for(i = 0; i < N; i++){
        if(str[i] == 'I'){
            x++;
            if(x > maximum){
                maximum = x;
            }
        }
        else if(str[i] == 'D'){
            x--;
        }
    }

    cout << maximum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U; 
    // int a,b;
    cin>>S;
    T=S;
    reverse(all(T));
    if(S!=T)
    {
        cout<<"No";
        return;
    }
    n=sz(S);
    U=S.substr(0,(n-1)/2);
    T=U;
    reverse(all(T));
    if(U!=T)
    {
        cout<<"No";
        return;
    }
    U=S.substr((n+3)/2,n);
    T=U;
    if(T!=U)
    {
        cout<<"No";
        return;
    }
    cout<<"Yes";
}
 
 
signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3604
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */

    int a = sc.nextInt();
    int b = sc.nextInt();

    if (13 <= a) {
      os.println(b);
    } else if (6 <= a) {
      os.println(b/2);
    } else {
      os.println(0);
    }
  }
}

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

int main() {
    vector<char> a;
    char c;
    c=getchar();
    while(c != '\n'){
        a.push_back(c);
        c=getchar();
    }
    string result;
    for (int i = 0; i < a.size() ; ++i) {
        if(a[i]>='a' && a[i]<='z') {
            result += a[i] - 32;
        }
        else if(a[i]>='A' && a[i]<= 'Z') {
            result += a[i] + 32;
        }
        else
            result+=a[i];
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3140
#include <stdio.h>
#include <math.h>
int main()
{
  int x,y,min,max,rem;

  scanf("%d %d",&x,&y);

  if((1<=x && x<=pow(10,9)) && (1<=y && y<=pow(10,9))){
  
    if(x==y){
      max=x;
    }
 
    if(x<y){
      max=y;
      min=x;
      while(min>0){
        rem=max%min;
        max=min;
        min=rem;
      }
    }

    if(x>y){
      max=x;
      min=y;
      while(min>0){
        rem=max%min;
        max=min;
        min=rem;
      }
    }
 
    printf("%d\n",max);
  }

  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
 
ll a,b,n;

int main()
{
    Fast;
    cin>>a>>b>>n;
    if(n<b)
    {
        cout<<(a*n)/b;
    }
    else
    {
        cout<<(a*(b-1))/b;
    }
}

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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        long A[] = new long[H + 1];
        long B[] = new long[W + 1];
        A[0] = 0;
        for(int i = 1; i <= H; i++){
            A[i] = -scan.nextInt();
        }
        B[0] = 0;
        for(int i = 1; i <= W; i++){
            B[i] = -scan.nextInt();
        }
        Arrays.sort(A);
        Arrays.sort(B);
        int pos1 = 0, pos2 = 0;
        long ans = 0;
        for(int loop = 0; loop < H + W; loop++){
            if(A[pos1] < B[pos2]){
                ans += pos2 * A[pos1];
                pos1 += 1;
            }else{
                ans += pos1 * B[pos2];
                pos2 += 1;
            }
        }
        System.out.println(-ans);
    }
}



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

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

  int64_t start = int64_t(sqrt(n));
  if(start*start == n) {
    cout<<2*(start-1)<<endl;
    return 0;
  }

  while(n%start != 0) start--;

  int64_t ans = (start-1) + (n/start-1);

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
/**
 * Я слил Atcoder Beginner Contest 172, решив всего две задачи!
 * Я не могу апнуть синего!
 * Я постоянно сливаю раунды, либо не решив тупую задачу, либо набрав штрафа!
 * Я постоянно уступаю всем своим друзьям и знакомым в контестах и нахожу этому оправдания!
 * Я постоянно придумываю сложные неверные решения к простым задачам!
 * -------------------------------------------------------------
 * -Решать сложные задачи
 * -Участвовать в контестах
 * -Делать виртуальные соревнования
 * -------------------------------------------------------------
 * Не уберу это, пока не начну нормально решать задачи, а не заниматься ерундой!!!
**/
  
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <__msvc_all_public_headers.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
 
typedef long long  ll;

#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define halt {cout<<"NO"; return 0;}

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int N = 200010;
const int INF = 1e8;
const ll LL_INF=1e10;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int questions=1;
// cin>>questions;
 
 while(questions--)
 {
           int a,b,c;
           cin>>a>>b>>c;
           int a1=a, b1=b, c1=c;
           a=a1+b1;
           b=a1+c;
           c=b1+c1;
           cout<<min(min(a,b),c);
           
   
   
          
          
          
         
 }
 
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 3620
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep( i, n )    for( lint i= 0  ; i <  (n) ; ++i )
#define all( v )       (v).begin(), (v).end()

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};


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

    UnionFind uf(N);

    rep( i, Q ) {
        int com, x, y;
        cin >> com >> x >> y;
        if( com == 0 ) {
            uf.unite( x, y );
        } else {
            cout << (uf.same(x,y) ? "1" : "0") << endl;
        }
    }
}



Measured memory_bytes: 3132
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

bool flag_3, flag_5, flag_7;
ll n,counts;


void func(string s,ll &counts) {
	if (s == "");
	else if (stoll(s)>n)return;
	flag_3 = false, flag_5 = false, flag_7 = false;
	if(s.size())repp(i, 0, s.size()) {
		if (s[i] == '3')flag_3 = true;
		else if (s[i] == '5')flag_5 = true;
		else if (s[i] == '7')flag_7 = true;
	}
	if (flag_3 == true && flag_5 == true && flag_7 == true)++counts;
	func(s+"7",counts);
	func(s +"5",counts);
	func(s +"3",counts);
}


int main() {
	cin >> n;
	string s = "";
	counts = 0;
	func(s,counts);
	cout << counts << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const int M = 100 + 5;
ll dp[N][M][3];
const ll mod = 1e9 + 7;
string num;
int d;
void add_Self(int &a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

int solve(int idx, int m, int la) {
    if (idx == num.size())
        return !m && la < 2;
    if (dp[idx][m][la] != -1)
        return dp[idx][m][la];
    int res = !m;
    for (int i = 0; i < 10; i++) {
        int tempm = m + i;
        int nxt = la;
        if (la == 0) {
            if (i == (num[idx] - '0'))
                nxt = 0;
            if (i < (num[idx] - '0'))
                nxt = 1;
            if (i > (num[idx] - '0'))
                nxt = 2;
        }
        add_Self(res, solve(idx + 1, tempm % d, nxt));
    }
    return dp[idx][m][la] = res;
}


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> num >> d;
    memset(dp, -1, sizeof dp);
    int res = 0;
    for (int i = 1; i < 10; i++) {
        int nxt = 0;
        if (i < (num[0] - '0'))
            nxt = 1;
        if (i > (num[0] - '0'))
            nxt = 2;
        add_Self(res, solve(1, i % d, nxt));
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 247296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // ifstream in("testcase_01");
    // cin.rdbuf(in.rdbuf());

    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    vector<ll> b(n);
    rep(i, n + 1) cin >> a.at(i);
    rep(i, n) cin >> b.at(i);
    ll ans = 0;
    rep(i, n) {
        ll left = min(a.at(i), b.at(i));
        ans += left;
        a.at(i) -= left;
        b.at(i) -= left;

        ll right = min(a.at(i + 1), b.at(i));
        ans += right;
        a.at(i + 1) -= right;
        b.at(i) -= right;
    }
    cout << ans;
}


Measured memory_bytes: 1792
w = input()
alph = ["a","b","c","d","e","f","g","h",
        "i","j","k","l","m","n","o","p","q",
        "r","s","t","u","v","w","x","y","z"]
ck = 0
for i in range(0, 26):
    if w.count(alph[i])%2 == 1:
        print("No")
        break
else:
    print("Yes")


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

int main(){
    
    string s; cin >> s;
    bool isCheck = true;

    int cnt = 0;
    string ans = "AC";

    if(s[0] != 'A') ans = "WA";
    for(int i = 1; i < s.length(); i++){
        if(isupper(s[i])){
            if(i == 1|| i == s.length()-1|| s[i] != 'C')    ans = "WA";
            cnt++;//大文字の個数増やす
        }
    } 

    if(cnt != 1)    ans = "WA";
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i<10;i++){
  std::cin>>A;
  if(B<A)B=A;
  else C<A?C=A:f=1;
 }
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

	int ans=0;
	for (int i = 1; i < n-1 ; ++i){
		if(a[i]<a[i+1]&&a[i]>a[i-1]||a[i]>a[i+1]&&a[i]<a[i-1])
			ans++;
		
	}

	cout<<ans<<endl;

	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
int array[5001];
int n,i,sum,k=0;
void tansaku(int a)
{
	k += array[a];
	if(k > sum)
	{
		sum = k;
	}
	if(a == n-1)return;
	tansaku(a+1);
}
int main(void)
{
	while(1)
	{
		for(i=0;i<5001;i++)
		{
			array[i] = 0;
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++)
		{
			scanf("%d",&array[i]);
		}
		sum = -10000000;
		for(i=0;i<n;i++)
		{
			tansaku(i);
			k = 0;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 620
def main():
    N,K = [int(e) for e in input().split()]
    asiba = [int(e) for e in input().split()]
    dp =[0] *N

    #初期化
    dp[0]=0
    dp[1]=abs(asiba[1]-asiba[0])

    for i in range(2,N):
        dp[i] = min(abs(asiba[i] - asiba[j]) + dp[j] for j in range(max(0, i - K), i))
    
    print(dp[N-1])
main()


Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,w;
	cin>>n>>w;
	ll dp[w+1][n+1];

	vector< pair < ll , ll > > v;
	ll weight,val;
	v.push_back({0,0});
	for(ll i=0;i<n;i++)
	{
		cin>>weight>>val;

		v.push_back({weight,val});
	
	}

	for(ll i=0;i<=w;i++)
	{
		for(ll j=0;j<=n;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;

			else
			if(i>=v[j].first)
			{
				dp[i][j]=max(v[j].second+dp[i-v[j].first][j-1],dp[i][j-1]);
			}
			else
			{
				dp[i][j]=dp[i][j-1];
			}
		}
	}

	// for(int i=0;i<=w;i++)
	// {
	// 	for(int j=0;j<=n;j++)
	// 	{
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<dp[w][n]<<endl;
	return 0;
}

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

int main()
{
    int n, i = 1;
    cin >> n;

    do {
        int x = i;

        if (x % 3 == 0) {
            cout << " " << i;
            continue;
        }

        do {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        } while (x);
    } while (++i <= n);

    cout << endl;

    return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

signed main(){
	cout<<fixed<<setprecision(7);
	int x;
	cin>>x;
	
	cout<<(x < 1200?"ABC":"ARC")<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
 int N,D;
int main(){
    cin >> N >> D;
    int i=1+D;
    int count =0;
    while(1){
        if(i-D<=N&&i+D>=N){
            count++;
            break;
        }else{
            count++;
            i+=1+2*D;
        }
    }
    printf("%d\n",count);
}

Measured memory_bytes: 3688
#include <stdio.h>

int main() {
    
    int vec[33] = {-1, 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};
    
    int n;
    scanf("%d", &n);
    
    printf("%d\n", vec[n]);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 0x3f //plus infinite

typedef struct item{
  string name;
  int number;
  int money;
}item;

string s[102],t[102];
item obj[102];


int main(){
  int n,m;
  cin >> n;
  int index = 1;
  string tmp;
  int flag;
  cin >> obj[index].name;
  obj[index].number++;
  obj[index++].money++;
  
  for(int i = 2;i <= n;i ++){
    flag = 0;
    cin >> s[i];
    
    for(int j = 1;j < index ;j++){    
      if(s[i] == obj[j].name){
	obj[j].number++;
	obj[j].money++;
	flag = 1;
      }
    }
    if(flag == 0){
      obj[index].name = s[i];
      obj[index].number = 1;
      obj[index].money = 1;
      index++;
    }
  }

//  cout << endl << "after half input " << endl;
//  for(int i = 1;i<index;i++){
//    cout << obj[i].name
//	 <<" "<<obj[i].number
//	 <<" "<<obj[i].money<<endl;
//  }
  

  cin >> m;
  for(int i = 1;i <= m;i++){
    cin >> t[i];
    for(int j = 1;j < index;j++){
      if(t[i] == obj[j].name){
	obj[j].money--;
	obj[j].number++;
      }
    }
  }

  int max = obj[1].money;
  for(int i = 2;i <= index;i++){
    if(max < obj[i].money){
      max = obj[i].money;
    }
  }
  if(max < 0){
    cout << 0 << endl;
  }else{
    cout << max << endl;
  }
  
}

/*文字列の辞書順について
 *C++の順序では'0'～'9'→'A'～'Z'→'a'～'z'の順に
 *                       なっていることに注意しましょう。
 */

/*行単位での入力
 * getline(cin,文字列変数);
 */


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

#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
const long long mod = 1e9+7;

using namespace std;
using ll = __int64_t;
using ull = unsigned long long;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

bool comp(const pair<int, ll>& p1, const pair<int, ll>& p2){
    return p1.second > p2.second;
}

void solve(){
    int n, a, b, c;
    cin >> n;
    cin >> a >> b >> c;

    if(n == 1){
        cout << max(max(a, b), c) << endl;
        return;
    }
    int dp[2][3];
    rep(i, 2){
        rep(j, 3){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = a;
    dp[0][1] = b;
    dp[0][2] = c;
    for(int i = 1; i < n; i++){
        cin >> a >> b >> c;
        for(int j = 0; j < 3; j++){
            if(j == 0){
                dp[1][j] = max(dp[0][1]+a, dp[0][2]+a);
            }else if(j == 1){
                dp[1][j] = max(dp[0][0]+b, dp[0][2]+b);
            }else{
                dp[1][j] = max(dp[0][0]+c, dp[0][1]+c);
            }
        }
        dp[0][0] = dp[1][0];
        dp[0][1] = dp[1][1];
        dp[0][2] = dp[1][2];
    }
    cout << max(max(dp[1][0], dp[1][1]), dp[1][2]) << endl;
}

int main() {
    solve();
    return 0;
}

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


int main()
{
	int n;
	cin>>n;
	ll ar[n+1];
	for(int i=1;i<=n;i++)
		cin>>ar[i];
	ll dp[n+1][n+1];

	for(int i=1;i<=n;i++)
	//	dp[0][i]=0.0;
	dp[0][0]=1.0;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1.0-ar[i]);
	//	cout<<dp[i][0]<<" "<<"UU"<<endl;
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			if(j!=i)
			dp[i][j]=dp[i-1][j]*(1.0-ar[i])+dp[i-1][j-1]*ar[i];
			else
			{
				dp[i][j]=dp[i-1][j-1]*ar[i];
			}
			//cout<<dp[i][j]<<" "<<"UU"<<endl;
		}
	}

	ll ans=0.0;
	for(int i=n/2+1;i<=n;i++)
	{
		ans+=dp[n][i];
	//cout<<ans<<endl;
	}

	cout<<setprecision(20)<<ans<<endl;


}

Measured memory_bytes: 140544
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		Integer[] intList = {a,b,c};
		Arrays.sort(intList, Comparator.reverseOrder());
		int sum = intList[0]*10 + intList[1] + intList[2];
		
		System.out.println(sum);
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long LL;
using namespace std;
LL fact[210000];
LL powmod(LL a, int n){
	if(n == 0) return 1;
	if(n % 2) return (a*powmod(a,n-1)) % MOD;
	LL c = powmod(a,n/2);
	return (c*c) % MOD;
}
LL inv(LL k){
	return powmod(k,MOD-2);
}
int main(){
	fact[0] = 1;
	for(LL i = 1; i < 210000; i++){
		fact[i] = (i*fact[i-1]) % MOD;
	}
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	// h-1 by w-1
	// (h-a,b-1),(a-1,w-b),  doesnt work
	//(h-a-1,b) (a,w-b-1)
	LL ans = 0;
	for(LL c = 0; (b + c) < w && (a + c) < h; c++){
		LL cur1 = (fact[h-a+b-1] * inv(fact[b+c])) % MOD;
		cur1 = (cur1 * inv(fact[h-a-c-1])) % MOD;
		LL cur2 = (fact[w+a-b-1] * inv(fact[a+c])) % MOD;
		cur2 = (cur2 * inv(fact[w-b-c-1])) % MOD;
		ans += (cur1*cur2) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;

}

Measured memory_bytes: 1920
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H, W, K;
    cin >> H >> W >> K;

    string S[H];
    REP(i, H) {
        cin >> S[i];
    }

    int ans = inf;
    REP(i, 1 << (H - 1)) {
        int nb = bcnt(i) + 1;
        vector<int> v(nb, 0);
        int tmp = bcnt(i);
        bool f = false;
        REP(w, W) {
            int h = 0;
            REP(j, H) {
                if (S[j][w] == '1') v[h]++;
                if (i >> j & 1) ++h;
            }

            if (*max_element(ALL(v)) > K) {
                if (f) {
                    tmp = inf;
                    break;
                }
                tmp++;
                f = true;
                v.assign(nb, 0);
                --w;
                continue;
            }

            f = false;
        }

        ans = min(ans, tmp);
    }

    cout << ans << endl;

}


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

int main() {
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes" << endl;
  }  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[11111],b[11111],c[11111],d[11111];
int main(){
    //freopen("fibsubseq.in","r",stdin);
    //freopen("fibsubseq.out","w",stdout);
    ll n,sum=0;
    cin>>n;
    for(ll i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        if(x>100000)break;
        if(y>=100000)sum+=100000-x+1;
        else
        sum+=y-x+1;
    }
    cout<<sum;
return 0;
}


Measured memory_bytes: 256
N = int(input())
dicta = {}
for i in range(N):
    word = input()
    dicta.setdefault(word, 0)
    dicta[word] += 1
word_c = list(dicta.items())
word_c.sort(key=lambda tup: tup[1], reverse=True)
max_len_word = [word_c[0][0]]
for j in range(1,len(word_c)):
    if word_c[j][1] == word_c[0][1]:
        max_len_word.append(word_c[j][0])
    else:
        break
max_len_word.sort()
for word in max_len_word:
    print(word)

Measured memory_bytes: 45788
################################################
#                                              #
#   author: raghav_0901 (Raghav Dalmia)        #
#   updated on: 19-09-2020,  5:32:05 pm IST   #
#                                              #
################################################

from math import *


def _in():
    return [int(x) for x in input().split(' ')]


if __name__ == "__main__":
    s = input()
    out = s + ("es" if s[-1] == "s" else "s")
    print(out)


Measured memory_bytes: 9024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;

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

struct edge{
	int to, cost;
};

int V, E, s;
vector<edge> e[100000];

vector<int> bellman_ford(){
	vector<int> d(V, INF);
	d[s]=0;
	
	while(1){
		bool flag=0;
		
		REP(i, V){
			REP(j, e[i].size()){
				edge ne=e[i][j];
				if(ne.cost!=INF && d[ne.to]>d[i]+ne.cost){
					d[ne.to]=d[i]+ne.cost;
					flag=1;
				}
			}
		}
		
		if(!flag) break;
	}
	
	return d;
}

int main(){
	cin >> V >> E >> s;
	
	REP(i, E){
		int f, t, d;
		cin >> f >> t >> d;
		e[f].push_back((edge){t, d});
	}
	
	vector<int> d;
	d=bellman_ford();
	
	REP(i, V){
		if(d[i]==INF) cout << "INF";
		else cout << d[i];
		cout << endl;
	}
}

Measured memory_bytes: 10508
#include <iostream>

using namespace std;

int n;
int dp[2][3];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		dp[1][0] = a+max(dp[0][1], dp[0][2]);
		dp[1][1] = b+max(dp[0][0], dp[0][2]);
		dp[1][2] = c+max(dp[0][0], dp[0][1]);

		swap(dp[0], dp[1]);
	}
	cout << max(dp[0][0], max(dp[0][1], dp[0][2])) << "\n";
	return 0;
}

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

int main() {
  int N,x=0;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(i%2==0)x+=a.at(i);
    else x-=a.at(i);
  }
cout<<x<<endl;
}


Measured memory_bytes: 256
import math
n = int(input())
a = list(map(int, input().split()))
c = [0 for i in range(n)]
s = 0
w = 0
for i, j in enumerate(a):
	if i+1 == j:
		c[i] = 1
for i, j in enumerate(c):
	if j == 1:
		w += 1
	else:
		s += math.ceil(w/2)
		w = 0
s += math.ceil(w/2)
print (s)


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

using namespace std;

const int mod = 1e9 + 7;

void add_self (int& a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string K;
  int D;
  cin >> K >> D;
  int lg = K.size();
  vector < vector < int > > dp(D, vector < int >(2));
  dp[0][0] = 1;
  for (int i = 0; i < lg; ++i) {
    vector < vector < int > > new_dp(D, vector < int >(2));
    for (int sum = 0; sum < D; ++sum)
      for (int sm_already : {0, 1})
        for (int digit = 0; digit < 10; ++digit) {
          if (digit > K[i] - '0' && !sm_already)
            break;
          add_self (new_dp[(sum + digit) % D][sm_already || (digit < K[i] - '0')],
                    dp[sum][sm_already]);
        }
    dp = new_dp;
  }
  int ans = (dp[0][0] + dp[0][1]) % mod;
  --ans;
  if (ans == -1)
    ans = mod - 1;
  cout << ans;
}


Measured memory_bytes: 3628
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
}  // namespace my
////////////////////////

int main() {
  string t;
  cin >> t;
  for (auto &ti : t) {
    if (ti == '?') ti = 'D';
  }
  cout << t << endl;
}

Measured memory_bytes: 3760
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑


void COMinit() {
	fac[0] = 1, fac[1] = 1, finv[0] = 1, finv[1] = 1, inv[1] = 1;
	for (int i = 2; i < 100005; ++i) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

//calc
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



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

	for (int i = 0; i < b; ++i) {
		cout << (ll)COM(a - b + 1, i + 1)*COM(b - 1, i) % MOD << endl;;
	}
}

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

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

const long long INF = 1e9;

long long dist (pair<long long, long long> a, pair<long long, long long> b) {
    long long s = abs(a.first - b.first);
    long long t = abs(a.second - b.second);
    return s + t;
}

int main() {
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> a, b;
    for (long long i = 0; i < n; i++) {
        long long s, t;
        cin >> s >> t;
        a.emplace_back(s, t);
    }
    for (long long i = 0; i < m; i++) {
        long long s, t;
        cin >> s >> t;
        b.emplace_back(s, t);
    }
    
    vector<long long> ans(n);
    for (long long i = 0; i < n; i++) {
        long long res = -1;
        long long d = INF;
        for (long long j = 0; j < m; j++) {
            if (chmin(d, dist(a[i], b[j]))) res = j + 1;
        }
        ans[i] = res;
    }
    
    for (const auto &e : ans) cout << e << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


const int Mxn = 1e5;
int dp[101][Mxn+1];
void solve()
{
  
  int n,w;
  cin >> n >> w;

  int an = -1;

  forf(i,0,n+1) forf(j,1,Mxn+1) dp[i][j] = INT_MAX;

  forf(i,1,n+1)
  {
    int cw,cv;
    cin >> cw >> cv;
    
    forf(j,1,Mxn+1)
    {
     dp[i][j] = dp[i-1][j]; 
     if(j>=cv) dp[i][j] = min(dp[i][j] , dp[i-1][j-cv]+cw);
    }

  }


  forf(i,1,Mxn+1)
  {
    if(dp[n][i]<=w) an = max(an ,i);
  }

  cout<<an<<"\n";
 
}


int32_t main()
{
  pr_init();
  //fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 82472
#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long LL;
int main() {
    int a,b,c,d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    printf("%d\n", min(a,b)+min(c,d));
    return 0;
}


Measured memory_bytes: 256
function Main(arg) {

  var n = arg.split("\n")[0].split(" ")[0] - 0;
  var m = arg.split("\n")[0].split(" ")[1] - 0;

  var A = new Array(n);
  var B = new Array(m);

  for (var i = 0; i < n; i++){
    A[i] = arg.split("\n")[i + 1].split("");
  }
  for (var i = 0; i < m; i++){
    B[i] = arg.split("\n")[n + 1 + i].split("");
  }
  
  for (var i = 0; i <= n - m; i++){
    for (var j = 0; j <= n - m; j++){
      var cnt = 0;
      for (var k = 0; k < m; k++){
        for (var l = 0; l < m; l++){
          if (A[i+k][j+l] == B[k][l]) cnt++;
        }
      }
      if (cnt == m * m) {
        console.log("Yes");
        return;
      }
    }
  }
  console.log("No");
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 20936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int q = sc.nextInt();

		array = new int[n];
		array[0] = 1;
		query = new int[q][4];
		for(int i = 0; i < q; i++){
			for(int j = 0; j < 4; j++){
				query[i][j] = sc.nextInt();
			}
		}

		System.out.println(dfs(1, n, m));
	}

	static int query[][];
	static int array[];

	static int dfs(int depth, int n, int m){
		if(depth == n){

			return calc();
		}

		int result = 0;
		for(int i = array[depth - 1] ; i <= m; i++){
			array[depth] = i;

			result = Math.max(result, dfs(depth + 1, n, m));
		}

		return result;
	}

	static int calc(){
		int result = 0;
		for(int i = 0; i < query.length; i++){
			if(array[query[i][1] - 1] - array[query[i][0] - 1] == query[i][2]){
				result += query[i][3];
			}
		}

		return result;
	}
}


Measured memory_bytes: 27824
#include <stdio.h>

int main();

int main(){
  int S, h, m, s;

  scanf("%d", &S);

  h=S/3600; /*????????????*/
  m=(S-h*3600)/60; /*(S??????h????????£????????????????§???°????????????)/???????????????\
?±????????????????60??§?????£??????*/
  s=S-h*3600-m*60; /*?????£????§?*/
     printf("%d:%d:%d\n", h, m, s);

  return 0;
}

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

using namespace std;

int gcd(int x, int y) {
    if(x < y) return gcd(y, x);
    if(y==0) return x;
    if(y<0) return gcd(x, -y);
    return gcd(y, x%y);
}

int main(void) {
    int n;

    cin >> n;
    if(n==1) {cout << 1 << endl; return 0;}

    vector<pair<int,int>> xy(n);
    for(auto &x: xy) cin >> x.first >> x.second;
    sort(xy.begin(), xy.end());

    auto idx = [&](int x, int y) {
        auto t = pair<int,int>(x,y);
        auto it = lower_bound(xy.begin(), xy.end(), t);
        if(it != xy.end() && *it == t) return it;
        return xy.end();
    };

    auto search = [&](int i, int j) {
        int p = xy[i].first - xy[j].first;
        int q = xy[i].second- xy[j].second;
        int g = gcd(p, q);

        vector<bool> b(n);
        auto dfs = [&](auto dfs, auto it) {
            int i = it - xy.begin();
            if(b[i]) return;
            b[i] = true;

            {
                auto itt = idx(it->first-p, it->second-q);
                if(itt != xy.end()) dfs(dfs, itt);
            }
            {
                auto itt = idx(it->first+p, it->second+q);
                if(itt != xy.end()) dfs(dfs, itt);
            }
            return;
        };

        int r = 0;
        for(int i=0; i<n; i++) {
            if(!b[i]) r++;
            dfs(dfs, xy.begin()+i);
        }
        return r;
    };

    int r = 1e9;
    for(int i=0; i<n; i++)
        for(int j=i+1; j<n; j++)
            r = min(r, search(i, j));
    cout << r << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int gcd(int a,int b){
	int amari;
	while((amari=a%b)!=0){
		a=b;
		b=amari;
	}
	return b;
}
int main(void){
	int a,b,n;
	while(scanf("%d %d",&a,&b)!=EOF){
		n=gcd(a,b);
		printf("%d %d\n",n,(a/n*b));
		fflush(stdout);
	}
	return 0;
}

Measured memory_bytes: 0
/**
 * Program name:Bubble Sort
 * author:Xin Peng
 * date:2020/1/5
 * Pragram problem source: AOJ
*/
#include <iostream>
using namespace std;

#define MAX 100

/**
 * @brief Trace display
 * @param data Data to display
 * @param length Length of the data
*/
void trace(int data[], int length)
{
    for (int i = 0; i < length; i++)
    {
        cout << data[i];
        if (i != length - 1)
        {
            cout << " ";
        }
    }
    cout << endl;
}

int BubbleSort(int data[], int length, bool ascent)
{
    bool continueOrNot = true;
    int count=0;

    for (int i = 0; (i < length - 1) && continueOrNot; i++)
    {
        continueOrNot = false;

        for (int j = length - 1; j > i; j--)
        {
            int tmp = 0;

            if (ascent && (data[j] < data[j - 1]))
            {
                tmp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = tmp;
                continueOrNot = true;
                count++;
            }
            else if (!ascent && (data[j] > data[j - 1]))
            {
                tmp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = tmp;
                continueOrNot = true;
                count++;
            }
        }
    }
    return count;
}

int main()
{
    int n;
    int R[MAX];
    int count = 0;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> R[i];
    }

    count=BubbleSort(R, n, true);
    trace(R, n);
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <queue>
#include <vector>

unsigned min_dist(const std::vector< std::vector<unsigned> > &c, unsigned s)
{
  std::vector<unsigned> d(10, -1);
  d[s] = 0;
  
  std::vector<unsigned> q;
  for (unsigned i = 0; i <= 9; ++i) {
    q.push_back(i);
  }
  
  while (!q.empty()) {
    unsigned min = -1, min_vertex = -1, min_index = -1;
    for (unsigned i = 0; i < q.size(); ++i) {
      if (min >= d[ q[i] ]) {
        min = d[ q[i] ];
        min_vertex = q[i];
        min_index = i;
      }
    }
    
    unsigned t = q[min_index];
    
    auto itr = q.begin();
    std::advance(itr, min_index);
    q.erase(itr);
    
    for (unsigned i = 0; i <= 9; ++i) {
      if (d[i] > d[t] + c[t][i]) {
        d[i] = d[t] + c[t][i];
      }
    }
  }
  
  return d[1];
}

int main()
{
  unsigned H, W;
  std::cin >> H >> W;
  
  std::vector< std::vector<unsigned> > c(10);
  for (unsigned i = 0; i <= 9; ++i) {
    c[i] = std::vector<unsigned>(10, 0);
    for (unsigned j = 0; j <= 9; ++j) {
      std::cin >> c[i][j];
    }
  }
  
  std::vector<unsigned> d(10, 0);
  for (unsigned s = 0; s <= 9; ++s) {
    if (s == 1) { continue; }
    
    d[s] = min_dist(c, s);
  }
  
  unsigned long long int S = 0;
  for (unsigned h = 0; h < H; ++h) {
    for (unsigned w = 0; w < W; ++w) {
      long A;
      std::cin >> A;
      
      if (A < 0) continue;
      
      S += d[A];
    }
  }
  std::cout << S <<std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int a = 0, b = 0;
	for (int i = 0 ; i < n ; i++) {
		if (s[i] == '(') b++;
		else b--;
		if (b < 0) {
			b = 0;
			a++;
		}
		
	}
	while (a--) cout << '(';
	cout << s;
	while (b--) cout << ')';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,i,j,temp,sum;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    cin>>m;
    int p[m],x[m];
    for(i=0;i<m;i++){
        cin>>p[i]>>x[i];
    }
    for(i=0;i<m;i++){
        temp=a[p[i]-1];
        a[p[i]-1]=x[i];
        sum=0;
        for(j=0;j<n;j++){
            sum+=a[j];
        }
        cout<<sum<<endl;
        a[p[i]-1]=temp;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n;
	cin>>n;
	FOR(i, 1, n){
		FOR(j, i+1, n+1){
			int x=i^j, ans=1;
			while(x){
				if(x&1){
					cout<<ans<<" \n"[j==n];
					break;
				}
				++ans;
				x/=2;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 512
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.math.min

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val C = sc.nextInt()
    val d = Array.ofDim[Int](C, C)
    for {
      i <- 0 until C
      j <- 0 until C
    } d(i)(j) = sc.nextInt()

    val init = Array.ofDim[Int](3, C)
    for {
      i <- 1 to N
      j <- 1 to N
    } {
      init((i + j) % 3)(sc.nextInt() - 1) += 1
    }

    var ans = Integer.MAX_VALUE
    for {
      i <- 0 until C
      j <- 0 until C
      k <- 0 until C
    } {
      if (i != j && i != k && j != k) {
        val dist = Array(i, j, k)
        val sum = (for {
          g <- 0 until 3
          c <- 0 until C
        } yield {
          val cost = d(c)(dist(g))
          val cnt = init(g)(c)
          cost * cnt
        }).sum
        ans = min(ans, sum)
      }
    }

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }


  @specialized
  def permutation[A, B](a: Array[A], z: B)(f: (Array[A], B) => B): B = {
    def swap(i: Int, j: Int): Unit = {
      val temp = a(i)
      a(i) = a(j)
      a(j) = temp
    }

    def step(n: Int, acc: B): B = n match {
      case 1 => f(a, acc)
      case _ =>
        val acc2 = (0 until n - 1).foldLeft(acc) { (acc0, i) =>
          val acc1 = step(n - 1, acc0)
          if (n % 2 == 0) {
            swap(i, n - 1)
          } else {
            swap(0, n - 1)
          }
          acc1
        }
        step(n - 1, acc2)
    }

    step(a.length, z)
  }
}


Measured memory_bytes: 70920
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int n;

int main() {
scanf("%d", &n);
printf("%d\n", (n - 2) * 180);
}




Measured memory_bytes: 764