akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

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

        //通常ループ
        while(true){
            c -= b;
            if(c <= 0){
                break;
            }
            a -= d;
            if(a <= 0){
                break;
            }
        }


        if(a > c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }


    }
}

Measured memory_bytes: 27040
#define ll long long
#define pb(x) push_back(x)
#define ppb() pop_back()
#define sr(a) sort(a.begin(),a.end())
#define min3(a,b,c) min(a,b) < min(b,c) ? min(a,b) : min(b,c)
#define max3(a,b,c) max(a,b) > max(b,c) ? max(a,b) : max(b,c)




#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

/*vector<int> a; int n,h;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>h; a.push_back(h);
}

for(int i=0;i<a.size();i++)
{

} */

int a,p;
cin>>a>>p;
int b=3*a+p;
if(p&0) cout<<b/3;
else {
    b=b/2;
}
cout<<b;
return 0;
}
/*try+lucky+ não= run
 made by Nguyễn Bá Hà

─────────▄──────────────▄
────────▌▒█───────────▄▀▒▌
────────▌▒▒▀▄───────▄▀▒▒▒▐
───────▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐
─────▄▄▀▒▒▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐
───▄▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀██▀▒▌
──▐▒▒▒▄▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄▒▒▌
──▌▒▒▐▄█▀▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐
─▐▒▒▒▒▒▒▒▒▒▒▒▌██▀▒▒▒▒▒▒▒▒▀▄▌
─▌▒▀▄██▄▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
─▌▀▐▄█▄█▌▄▒▀▒▒▒▒▒▒░░░░░░▒▒▒▐
▐▒▀▐▀▐▀▒▒▄▄▒▄▒▒▒▒▒░░░░░░▒▒▒▒▌
▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒░░░░░░▒▒▒▐
─▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
─▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
──▀▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▌
────▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀
───▐▀▒▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀
──▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀

*/


Measured memory_bytes: 256
# ABC069 D - Grid Coloring
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
L = []

for i in range(N):
    for j in range(A[i]):
        L.append(i+1)

M = [[] for _ in range(H)]

idx = 0
for i in range(H):
    for j in range(W):
        M[i].append(L[idx])
        if i%2 == 1:
            M[i].sort(reverse=True)
        idx += 1

for m in M:
    print(*m)


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

int main()
{
    long long a;
    while(~scanf("%lld",&a))
    {
        long long ms,i;
        for(i=0;i*i<=a;i++)
        {
            ms=i*i;
        }
        printf("%lld\n",ms);
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int change =0;
		int num[] = new int[count];
		for(int i=0; i<count; i++) {
			num[i]=sc.nextInt();
		}

		for(int i=count-1; i>0; i--) {
			for(int j=0; j<i; j++) {
				if(num[j]>num[j+1]) {
					int tmp =num[j];
					num[j]=num[j+1];
					num[j+1]=tmp;
					change += 1;
				}
			}
		}
		if(count !=1){
		   for(int i = 0;i < count -1;i++){
			      System.out.print(num[i] + " ");
			    }
		}
			    System.out.println(num[count - 1]);
			    System.out.println(change);
	}

}


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

int main()
{
    int a,b;
    string s,u,t;

    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s)
        cout<<a-1<<" "<<b<<endl;
    else
        cout<<a<<" "<<b-1<<endl;
}


Measured memory_bytes: 256
sx,sy,i,x,y,n;
xx[12],yy[12];
q[999999],t,h,p,ok,c,k;
dx1[]={2,2,2,1,0,-1,-2,-2,-2,-1,0,1};
dy1[]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
used[11111];
main()
{
  for(;scanf("%d%d",&sx,&sy),sx;puts(ok?"OK":"NA")){
    for(i=scanf("%d",&n);i<=n;)scanf("%d%d",xx+i++,yy+i);
    //for(i=1;i<=n;i++)printf("%d %d\n",xx[i],yy[i]);
    for(ok=t=h=0,q[t++]=sx*10+sy;t!=h;){
      p=q[h++];
      c=p/100;
      //printf("%d %d %d\n",p/100,p/10%10,p%10);
      if(c&&(abs(xx[c]-p/10%10)>1||abs(yy[c]-p%10)>1))continue;
      if(c==n){ok=1;break;}
      for(i=0;i<12;i++){
        x=p/10%10+dx1[i];
        y=p%10+dy1[i];
        k=(c+1)*100+x*10+y;
        if(x>=0&x<10&y>=0&x<10)q[t++]=k,used[k]=1;
      }
    }
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define INF (2000000000)
#define MOD (1000000007)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;

int L;
map<int, int> maparray;

int maxi(int a)
{
	char s[16];
	sprintf(s, "%0*d", L, a);
	
	sort(s, s + L);
	reverse(s, s + L);
	
	int n;
	sscanf(s, "%d", &n);
	return (n);
}

int mini(int a)
{
	char s[16];
	sprintf(s, "%0*d", L, a);
	
	sort(s, s + L);
	
	int n;
	sscanf(s, "%d", &n);
	return (n);
}
	
int main()
{
	int a;
	while (scanf("%d %d", &a, &L), a + L){
		int i = 0;
		while (!maparray.count(a)){
			maparray.insert(make_pair(a, i++));
			
			a = maxi(a) - mini(a);
		}
		
		printf("%d %d %d\n", maparray[a], a, i - maparray[a]);
		
		maparray.clear();
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc161/abc161_d.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// [桁][未満フラグ][nonzeroフラグ][last][lunlun]
ll dp[20][2][2][10][2];

ll memo(string &S, int i, int smaller, int nonzero, int last, int l) {
  if (i >= S.size()) return l;
  if (dp[i][smaller][nonzero][last][l] != -1)
    return dp[i][smaller][nonzero][last][l];

  ll ret = 0;
  int current = S[i] - '0';
  int limit = smaller ? 9 : current;
  for (int d = 0; d <= limit; d++) {
    int lun = 1;
    if (nonzero) lun = abs(d - last) <= 1;

    ret +=
        memo(S, i + 1, smaller || d < current, nonzero || d > 0, d, l && lun);
  }
  return dp[i][smaller][nonzero][last][l] = ret;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int K;
  cin >> K;

  ll l = 0, r = LINF;
  while (l + 1 < r) {
    ll x = (l + r) / 2;
    string s = to_string(x);
    memset(dp, -1, 20 * 2 * 10 * 2 * 2 * sizeof(ll));
    ll cnt = memo(s, 0, 0, 0, 0, 1);

    if (cnt <= K) {
      l = x;
    } else {
      r = x;
    }
  }

  cout << r << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=a;i<ll(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    ll a[6];
    while(1){
        ll S=0;
        rep(i,6){
            cin>>a[i];
            S+=a[i];
        }
        if(S==0)break;
        rep(i,3)a[i]+=a[i+3];
        ll res=0;
        ll M=min({a[0],a[1],a[2]});
        M=min(M,2LL);
        for(int i=0;i<=M;i++){
            ll t=0;
            rep(j,3)t+=(a[j]-i)/3;
            res=max(res,t+i);
        }
        printf("%lld\n",res);
    }
}

Measured memory_bytes: 1136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
 
using namespace std;

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
 
int main(){
    int N;

    cin >> N;

    int ans = INT_MAX;
    for(int a = 1; a < N; a++){
        int b = N - a;
        int digitsum = findSumOfDigits(a) + findSumOfDigits(b);

        if(digitsum < ans) ans = digitsum;
    }

    cout << ans << endl;

    return 0;
}

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

const int INF = 1000000009;
const long LINF = 1123456789012345678;

typedef std::pair<long, long> P;
long cost[100005][2];//[0]:yen s -> i, [1]:snuuk i -> t

long n, m, s, t;

struct Edge{
	long to;
	long cost[2];
};

std::vector<Edge> edge[100005];

long ans[100005];
//*
void dijkstra(int a){
	std::priority_queue<P, std::vector<P>, std::greater<P> > que;
	long st;
	if(a == 0){
		st = s;
	}else{
		st = t;
	}
	cost[st][a] = 0;
	que.push(P(0, st));
	
	while(!que.empty()){
		P p = que.top();
		que.pop();
		long v = p.second;
		if(cost[v][a] < p.first){
			continue;
		}
		for(int i = 0; i < edge[v].size(); i++){
			Edge e = edge[v][i];
			if(cost[e.to][a] > cost[v][a] + e.cost[a]){
				cost[e.to][a] = cost[v][a] + e.cost[a];
				que.push(P(cost[e.to][a], e.to));
			}
		}
	}
}
	
//*/
int main(){
	std::cin >> n >> m >> s >> t;
	for(int i = 0; i <= n; i++){
		cost[i][0] = LINF;
		cost[i][1] = LINF;
	}
	for(int i = 0; i < m; i++){
		long u, v, a, b;
		std::cin >> u >> v >> a >> b;
		Edge e1 = {u, {a, b}};
		Edge e2 = {v, {a, b}};
		edge[v].push_back(e1);
		edge[u].push_back(e2);
	}
	/*
	for(int i = 1; i <= n; i++){
		printf("%d\n", i);
		for(int j = 0; j < edge[i].size(); j++){
			printf("  -> %ld (%ld, %ld)\n", edge[i][j].to, edge[i][j].cost[0], edge[i][j].cost[1]);
		}
	}
	//*/
	dijkstra(0);
	dijkstra(1);
	/*
	for(int i = 0; i < 2; i++){
		for(int j = 1; j <= n; j++){
			printf("%ld  ", cost[j][i]);
		}
		printf("\n");
	}
	//*/
	ans[n] = cost[n][0] + cost[n][1];
	for(int i = n-1; i > 0; i--){
		ans[i] = std::min(cost[i][0] + cost[i][1], ans[i+1]);
	}
	for(int i = 1; i <= n; i++){
		printf("%ld\n", 1000000000000000 - ans[i]);
	}
	return 0;
}


Measured memory_bytes: 13100
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int n,b[100002]={},c;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>c;
        b[c]+=1; b[c+1]+=1; b[c+2]+=1;
    }
    int m=0;
    for(int i=0;i<100002;i++){
        m=max(m,b[i+1]);
    }
    cout<<m;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
 
int main(){
 
    int i,n,a,b,c;
 
    scanf("%d",&n);
 
    for(i = 0; i < n; i++){
        scanf("%d%d%d",&a,&b,&c);
 
        if((a * a == b * b + c * c)||(b * b == a * a + c * c)||(c * c == a * a + b * b)){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
 
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;

bool life[105];

int main()
{
    int n,k,d,a;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&d);
        while(d--)
        {
            scanf("%d",&a);
            life[a]=1;
        }
    }
    a=0;
    for(int i=1;i<=n;i++)
    {
        if(!life[i])
            a++;
    }
    printf("%d\n",a);
    return 0;
}


Measured memory_bytes: 3808
loop do
    x, y, s = gets.split.map(&:to_i)
    break if x == 0
    komi2nuki = Hash.new(-Float::INFINITY)
    (1..s-1).map do |n|
        k = n * (100 + x) / 100
        komi2nuki[k] = n
    end
    p (1..s/2).map {|u| komi2nuki[u] * (100 + y) / 100 + komi2nuki[s-u] * (100 + y) / 100}.max
end



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

long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main(void) {
	int n, sum = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				int a = gcd(i, j);
				sum += gcd(a, k);
			}
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
int N,M,X,Y,Z;
int x[105],y[105];
int main(){
	int max,min;
	scanf("%d%d%d%d",&N,&M,&X,&Y);
	max=X;
	min=Y;
	for(int i=1;i<=N;i++){
		scanf("%d",&x[i]);
		if(x[i]>max)
			max=x[i];
	}
	for(int i=1;i<=M;i++){
		scanf("%d",&y[i]);
		if(y[i]<min)
			min=y[i];
	}
	if(min-max<=0)
		printf("War");
	else
		printf("No War");
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std; 
#define MAXN 20
#define MAXA 100
#define MAXB 2000
int main(int argc,char const* argv[])
{
  int n,a,b,ans;
  cin >> n >> a >> b;
  ans=min(n*a,b);
  cout << ans << endl;
  return 0;
}


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

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

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

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

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

signed main(){
    int N, M, S;
    while( cin >> N >> M >> S, N | M | S ){
        vector<PP> hline( M );
        REP( i, M ) cin >> hline[i].first >> hline[i].second.first >> hline[i].second.second;
        sort( ALL( hline ), greater<PP>() );

        int hight = INF, cur = S;
        for( auto nl : hline ){
            hight = nl.first;
            if( nl.second.first == cur ){
                cur = nl.second.second;
            }else if( nl.second.second == cur ){
                cur = nl.second.first;
            }
        }

        cout << cur << endl;
    }
}



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

int main() {
    int H, W;
    for(int i=0; ; i++){
    cin >> H >> W;
    if(H==0 && W==0) break;
    for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
        if(1<=i && i<=H-2 && 1<=j && j<=W-2) cout << ".";
        else cout << "#";
    }
    cout << endl;
    }
    cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3088
#include<stdio.h>

int main(){
	unsigned long long a,b,c;
	scanf("%lld %lld",&a,&b);
	c=a*b;
	if(a==1||b==1)printf("1");
	else if(c%2==0)printf("%lld",c/2);
	else printf("%lld",c/2+1);
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>

using namespace std;

char tab[1007][1007];
int dp[1007][1007];

int main()
{
    int N,M;
    cin >> N >> M;
    for(int i=1; i<=N; i++)
        for(int j=1; j<=M; j++)
            cin >> tab[i][j];
    dp[1][1]=1;
    for(int i=1; i<=N; i++)
    {
        for(int j=1; j<=M; j++)
        {
            if(tab[i][j] == '.') dp[i][j]=max(dp[i][j], dp[i-1][j]+dp[i][j-1]);
            dp[i][j]%=1000000007;
        }
    }
    cout << dp[N][M];
}

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

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

	string rS = {S.rbegin(), S.rend()};
	int cnt = 0;
	rep(i, S.size() / 2) {
		if(S[i] != rS[i]) cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

void solve() {
	int N; cin >> N;
	vector<int>v(N);
	REP(i, N)cin >> v[i];
	int ans = 0;
	REP(i, N - 1) {
		if (v[i] == i + 1) {
			ans++;
			swap(v[i], v[i + 1]);
		}
	}
	if (v[N - 1] == N)ans++;
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
const int maxn=105;
int v[maxn],plate[maxn];

int main(){
    int n,k,r;
    scanf("%d %d",&n,&k);
//    vector<int> v(n),plate(n);
    for(int i=0;i<n;++i){
        scanf("%d",&v[i]);
    }
    r=min(n,k);
    int ans=0;
    for(int A=0;A<=r;++A){
        for(int B=0;B<=r-A;++B){
            int i,j;
            for(i=0;i<A;++i){
                plate[i]=v[i];
            }
            for(j=0;j<B;++j){
                plate[i+j]=v[n-1-j];
            }
            sort(plate,plate+A+B);
            i=0;
            while(i<k-(A+B)&&plate[i]<0){
                ++i;
            }
            int tmp=0;
            while(i<A+B){
                tmp+=plate[i++];
            }
            ans=max(ans,tmp);
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    string s; cin >> s;

    for (int i = 0; i < s.length(); ++i) {
        char t = s[i] + n;

        if (t > 'Z') t = (char)(t - 26);

        cout << t;
    }

    cout << endl;
}

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

int main()
{
    int judge = 0;
    char s[202], t[101];
    scanf("%s %s", s, t);
    char s_copy[101];
    
    strcpy(s_copy, s);
    
    strcat(s, s_copy);
    
    if(strstr(s, t)!=NULL) judge = 1;

    if(judge==1) printf("Yes");
    else printf("No");

    return 0;
}

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

using namespace std;

int main(){
  string str;
  getline(cin,str);

  char nw;
  for(char e : str){
    //cout<<e<<endl;
    switch(e){
      case '2': cout<<"k"; break;
      case '3': cout<<"s"; break;
      case '4': cout<<"t"; break;
      case '5': cout<<"n"; break;
      case '6': cout<<"h"; break;
      case '7': cout<<"m"; break;
      case '8': cout<<"y"; break;
      case '9': cout<<"r"; break;
      case 'T': if(nw == '0'){
                  cout<<"w";
                }
                cout<<"a";
                break;
      case 'L': cout<<"i"; break;
      case 'U': if(nw == '0'){
                  cout<<"nn";
                }
                else{
                  cout<<"u";
                }
                break;
      case 'R': cout<<"e"; break;
      case 'D': if(nw == '0'){
                  cout<<"w";
                }
                cout<<"o";
                break;
      default : break;
    }
    nw = e;
    //cout<<nw<<endl;
  }
  cout<<endl;
  return 0;

}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    list<int>L[1010];
    list<int>::iterator it;
    int n,q;
    cin>>n>>q;
    while(q--){
        int a,t,x;
        cin>>a;
        if(a==0){
            cin>>t>>x;
            L[t].push_back(x);
        }
        if(a==1){
            cin>>t;
            for(it=L[t].begin();it!=L[t].end();it++){
                if(it!=L[t].begin())cout<<" ";
                cout<<*it;
            }
            cout<<endl;
        }
        if(a==2){
            cin>>t>>x;
            L[t].splice(L[x].end(),L[t]);
        }
    }
}


Measured memory_bytes: 18652
n = int(input())
a = []
b = []
c = []
for i in range(n):
    at,bt,ct = map(int,input().split())
    a.append(at)
    b.append(bt)
    c.append(ct)
dp = [[0,0,0] for i in range(n)]
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]
for i in range(1,n):
    dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2])
    dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2])
    dp[i][2] = c[i] + max(dp[i-1][0],dp[i-1][1])
print(max(dp[-1]))

Measured memory_bytes: 34592
require 'set'; require 'prime'
INF=Float::INFINITY
n = gets.chomp.to_i

map = Array.new(10){Array.new(10,0)}
1.upto(n).each do |i|
  if i < 10
    head = i
  elsif i < 100
    head = i/10
  elsif i < 1000
    head = i/100
  elsif i < 10000
    head = i/1000
  elsif i < 100000
    head = i/10000
  elsif i < 1000000
    head = i/100000
  end
  tail = i%10
  map[head][tail] += 1
end

ans = 0
1.upto(9).each do |i|
  1.upto(9).each do |j|
    ans += map[i][j] * map[j][i]
  end
end
puts ans

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
int main(){
 int x,a,b;
  cin >> x >> a >> b;
  x-=a,x%=b;
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

//最大公約数
template<class T>
inline T GCD(T m, T n)
{
	T temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
template<class T>
inline T LCM(T m, T n)
{
	return m * n / GCD(m, n);
}

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

	vector<int> l(n), r(n);
	l[0] = w[0]; r[n - 1] = w[n - 1];
	for (int i = 1; i < n; ++i) { l[i] += w[i] + l[i - 1]; }
	for (int i = n - 2; i >= 0; --i) { r[i] += w[i] + r[i + 1]; }
	vector<int> ans(n-1);
	for (int i = 0; i < n-1; ++i) { ans[i] = abs(r[i+1] - l[i]); }


	cout << *min_element(ans.begin(),ans.end()) << endl;
	return 0;
}

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

int main()
{
    long long x;
    cin >> x;

    long long mutari(x / 11ll);
    mutari <<= 1ll;
    x %= 11ll;
  //  cout << x << '\n';
    if (x != 0ll) {
        if (!(mutari & 1ll))
            x -= 6ll, mutari++;
        else
            x -= 5ll, mutari++;
        if (x > 0)
            mutari++;
    }

    cout << mutari;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};

const int MAX_H = 505;
const int MAX_W = 505;

int a[MAX_H][MAX_W];

struct Move{
	int cy;
	int cx;
	int ny;
	int nx;
};

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

	int H, W; cin >> H >> W;
	rep (i, H)rep(j, W) cin >> a[i][j];

	vector<int> path; path.clear();
	rep (i, H){
		if (i % 2 == 0){
			rep (j, W){
				path.push_back(i * W + j);
			} // end rep
		}else{
			for (int j = W - 1; j >= 0; --j){
				path.push_back(i * W + j);
			} // end for
		} // end if
	} // end rep

	vector<Move> res; res.clear();
	rep (i, (int)path.size() - 1){
		int cr = path[i] / W;
		int cc = path[i] % W;
		if (a[cr][cc] % 2 != 0){
			int nr = path[i+1] / W;
			int nc = path[i+1] % W;
			res.push_back((Move){cr+1,cc+1,nr+1,nc+1});
			--a[cr][cc];
			++a[nr][nc];
		} // end if
	} // end rep

	int N = (int)res.size();
	cout << N << endl;
	rep (i, N){
		cout << res[i].cy << ' ' << res[i].cx << ' ' << res[i].ny << ' ' << res[i].nx << endl;
	} // end rep

	return 0;
}

Measured memory_bytes: 6128
#include <iostream>
#include<string>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
#include <limits>
#include <numeric>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL

int main(){
  int n;cin>>n;
  vector<P>r(n),b(n);
  rep(i,n)cin>>r[i].fi>>r[i].se;
  rep(i,n)cin>>b[i].fi>>b[i].se;
  sort(ALL(b));

  int ans=0;
  bool r_used[n];
  rep(i,n)r_used[i]=0;
  rep(i,n){
    P best=make_pair(0,-MAX);
    rep(j,n){
      if(r[j].fi<b[i].fi && r[j].se<b[i].se && r_used[j]==0){
        if(best.se<r[j].se){
          best.fi=j;best.se=C_MAX(best.se,r[j].se);
        }
      }
    }
    if(best.se!=-MAX){
      r_used[best.fi]=1;
      ans++;
    }

  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  int64_t kasan=0;
  cin >> n;
  vector<int64_t> a(n);
  vector<int64_t> b(1000000);
  rep(i,n) cin >> a.at(i);
  rep(i,n) b.at(a.at(i))++;
//  cout << b.at(1) <<endl;
//  cout << b.at(2) <<endl;
  rep(i,1000000){
    kasan += (b.at(i)-1)*(b.at(i))*0.5;
  }  
  for(int i=0;i<n;i++){
    int64_t sa =  (b.at(a.at(i))-1)*(b.at(a.at(i)))*0.5 - (b.at(a.at(i))-2)*(b.at(a.at(i))-1)*0.5;   
    cout << kasan - sa <<endl;
  }
}

Measured memory_bytes: 11904
import sys
from collections import deque


fin = sys.stdin.readline
N = int(fin())
adj = [[] for _ in range(N)]
w = {}
for _ in range(N - 1):
    a, b, c = [int(elem) for elem in fin().split()]
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)
    w[a, b] = c
    w[b, a] = c

Q, K = [int(elem) for elem in fin().split()]
K -= 1
queries = tuple(tuple(int(elem) - 1 for elem in fin().split()) for _ in range(Q))
dist_from_root = {K: 0}
nodes = deque()
nodes.append(K)
while nodes:
    node = nodes.popleft()
    dist = dist_from_root[node]
    for neighbor in adj[node]:
        if neighbor not in dist_from_root:
            dist_from_root[neighbor] = dist + w[node, neighbor]
            nodes.append(neighbor)

for x, y in queries:
    print(dist_from_root[x] + dist_from_root[y])


Measured memory_bytes: 119452
#include<stdio.h>
int main() 
{
    long long int n, m, x, sum=0,i;
    scanf("%lli %lli", &n, &m);
    for(i=0;i<m;i++) 
    {
    	scanf("%lli", &x) ;
    	sum+=x;
   } 
   if(sum<=n) 
   printf("%lli\n", n-sum) ;
   else
   printf("-1\n") ;
   return 0;
} 

Measured memory_bytes: 1704
use std::io::*;
use std::str::FromStr;
use std::cmp::*;

fn func(a: &Vec<i64>, dp: &mut Vec<Vec<i64>>, f: usize, l: usize, taro: bool, inf: i64) -> i64 {
    if f == l {
        return a[f] * if taro {1} else {-1};
    }

    let mut res;
    if taro {
        res = -inf;
        if dp[f+1][l] == inf {
            let po = func(a, dp, f+1, l, false, inf);
            dp[f+1][l] = po;
        }
        res = max(res, dp[f+1][l] + a[f]);

        if dp[f][l-1] == inf {
            let po = func(a, dp, f, l-1, false, inf);
            dp[f][l-1] = po;
        }
        res = max(res, dp[f][l-1] + a[l]);
    } else {
        res = inf;
        if dp[f+1][l] == inf {
            let po = func(a, dp, f+1, l, true, inf);
            dp[f+1][l] = po;
        }
        res = min(res, dp[f+1][l] - a[f]);

        if dp[f][l-1] == inf {
            let po = func(a, dp, f, l-1, true, inf);
            dp[f][l-1] = po;
        }
        res = min(res, dp[f][l-1] - a[l]);
    }
    dp[f][l] = res;
    res
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();
    let inf: i64 = 1_i64 << 60;
    
    // dp[i][j] = 区間[i,j]におけるX-Yの最大値
    let mut dp: Vec<Vec<i64>> = vec![vec![inf; n+1];n+1];
    println!("{}", func(&a, &mut dp, 0, n-1, true, inf));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main( void ) {
    char S[7];

    scanf("%s", S);

    if ( strcmp(S, "Sunny") == 0 ) {
        printf("Cloudy");
    } else if ( strcmp(S, "Cloudy") == 0 ) {
        printf("Rainy");
    } else {
        printf("Sunny");
    }

    return 0;
}

Measured memory_bytes: 128
if __name__ == '__main__':
    N = int(input())
    for _ in range(N):
        a = input()
        b = input()
        c = str(int(a) + int(b))
        if len(a) > 80 or len(b) > 80 or len(c) > 80:
            print("overflow")
        else:
            print(c)


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
const long long MOD=1000000007LL;
const long long INFL=1LL << 60;
const int INF=1<<29;

const int MAX = 220000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int 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 N,A,B,C;
    cin >>N>>A>>B>>C;
    A=A*inv[100-C]%MOD;
    B=B*inv[100-C]%MOD;

    vector<ll> Apows(N+1),Bpows(N+1);
        
    Apows[0]=1;Bpows[0]=1;
    for(int i=1;i<=N;i++){
        Apows[i]=Apows[i-1]*A%MOD;
        Bpows[i]=Bpows[i-1]*B%MOD;
    }

    ll ans=0;
    for(ll i=N;i<2*N;i++){
        ans+=COM(i-1,N-1)*(Apows[N]*Bpows[i-N]%MOD+Apows[i-N]*Bpows[N]%MOD)%MOD*i%MOD;
        ans=ans%MOD;
    }
    ans=ans*100%MOD*inv[100-C]%MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}

int board[22][22];
long long dp[22][(1 << 21)];
int n;
long long solve(int idx,int mask)
{
    if(idx == n)
        return 1;
    if(dp[idx][mask] != -1)
        return dp[idx][mask];
    long long C = 0;
    for(int i = 0;i < n;i++)
    {
        if(board[idx][i] == 1 && (mask & (1 << i)) == 0)
            C += solve(idx + 1,mask | (1 << i)) % MOD,C %= MOD;
    }
    return dp[idx][mask] = C;
}
int main()
{
    IO;
    cin >> n;
    memset(dp,-1,sizeof dp);
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
            cin >> board[i][j];
    }
    cout << solve(0,0);
    return 0;
}


Measured memory_bytes: 360704
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
ll a[2*100002];
ll vis[2*100002];
int main(){
    ll n,k;
    cin>>n>>k;

    for1(i,n) cin>>a[i];

    ll cur=1;
    ll t=0;
    while(1){
        t++;
        if(vis[cur]!=0) break;
        vis[cur]=t;
        cur=a[cur];
    }
    k++;
    if(k<=t){
        ll c=1;
        k--;
        while(k--){
        c=a[c];
        }
        cout<<c;
    }
    else{
        //cout<<cur<<" ";
        ll c=cur;
        k-=vis[cur];
        k=k%(t-vis[cur]);
        while(k--){
        
        //vis[c]=t;
        c=a[c];
    }
    cout<<c;
    }
}

Measured memory_bytes: 6736
n=int(raw_input())
s=[raw_input() for _ in xrange(n)]
cnt=[[0]*26 for _ in xrange(n)]
for i in xrange(n):
    for j in xrange(len(s[i])):
        cnt[i][ord(s[i][j])-ord("a")]+=1
ans=""
for j in xrange(26):
    tmp=10**9
    for i in xrange(n):
        tmp=min(tmp,cnt[i][j])
    ans+=chr(j+ord("a"))*tmp
print ans

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                if (500 * i + 100 * j + 50 * k == x) {
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
long long conv(char s){
	return (ll)s-'0';
}
long long dfs(string s,int cur,ll a,ll b){
	//curの位置で分けるか分けないか。分けるならb、分けないならaへ。
	if(cur==s.size()){
		return a+b;
	}
	ll ret=0;
	ll conved=10*b+conv(s[cur]);
	ret+=dfs(s,cur+1,a+conved,0);
	ret+=dfs(s,cur+1,a,conved);
	return ret;
}
int main(){
	string s;	cin>>s;
	ll ret=dfs(s,0,0,0);
	cout<<ret/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main()
{
	int A, B, C;
	int tmp;

	cin >> A >> B >> C;

	if (A%B == C) {
		cout << "YES" << endl;
		return 0;
	}

	tmp = A % B;

	for (int i = 2; (A*i) % B != tmp; i++) {
		if (A*i%B == C) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int a,sum=0;
	for(int i=0;i<5;i++){
		cin>>a;
		if(a<40){a=40;}
		sum+=a;
	}
	sum/=5;
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int n,m,k,MOD;
int fac[10005],inv[10005],fac_inv[10005];
void init(){
	fac[0]=fac_inv[0]=inv[1]=1;
	for(int i=1;i<=10000;++i){
		fac[i]=1ll*fac[i-1]*i%MOD;
		if(i>1) inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
		fac_inv[i]=1ll*fac_inv[i-1]*inv[i]%MOD;
	}
}
inline int fpow(int x,int n,int ret=1){
	for(;n;n>>=1,x=1ll*x*x%MOD)
		n&1?ret=1ll*ret*x%MOD:0;
	return ret;
}
int f[105][105],g[105][105],t[105];
void mul1(){
	for(int x=n;x>=0;--x)
	for(int y=0;y<=m;++y){
		f[x][y]=1ll*f[x][y]*t[0]%MOD;
		for(int i=0;i<x;++i)
			f[x][y]=(f[x][y]+1ll*f[i][y]*t[x-i])%MOD;
	}
}
void mul2(){
	for(int x=0;x<=n;++x)
	for(int y=m;y>=0;--y){
		f[x][y]=1ll*f[x][y]*t[0]%MOD;
		for(int i=0;i<y;++i)
			f[x][y]=(f[x][y]+1ll*f[x][i]*t[y-i])%MOD;
	}
}
int pw1[10005],pw2[10005],pw3[10005];
int main(){
	scanf("%d%d%d%d",&n,&m,&k,&MOD);
	init();
	f[0][0]=1;
	for(int kk=1;kk<=k;++kk){
		int a=k-kk+1,b=k-kk,c=kk;
		pw1[0]=pw2[0]=pw3[0]=1;
		for(int i=1;i<=n*m;++i){
			pw1[i]=1ll*pw1[i-1]*(k-kk+1)%MOD;
			pw2[i]=1ll*pw2[i-1]*(k-kk)%MOD;
			pw3[i]=1ll*pw3[i-1]*kk%MOD;
		}
		for(int x=0;x<=n;++x)
		for(int y=0;y<=m;++y)
			f[x][y]=1ll*f[x][y]*fpow(pw1[x*y],MOD-2)%MOD*pw3[x*y]%MOD;
		for(int i=0;i<=n;++i) 
			t[i]=1ll*fac_inv[i]*pw3[i*m]%MOD;
		mul1();
		for(int i=0;i<=m;++i) 
			t[i]=1ll*fac_inv[i]*pw3[i*n]%MOD;
		mul2();
		if(k==kk){
			for(int x=0;x<=n;++x)
			for(int y=0;y<=m;++y)
				f[x][y]=1ll*f[x][y]*pw1[x*y]%MOD*fpow(pw3[x*y],MOD-2)%MOD;
			break;
		}
		for(int x=0;x<=n;++x)
		for(int y=0;y<=m;++y)
			f[x][y]=1ll*f[x][y]*pw1[x*y]%MOD*fpow(pw2[x*y],MOD-2)%MOD;
		for(int i=0;i<=n;++i) 
			t[i]=1ll*fac_inv[i]*pw3[i*m]%MOD*(i&1?MOD-1:1)%MOD;
		mul1();
		for(int i=0;i<=m;++i) 
			t[i]=1ll*fac_inv[i]*pw3[i*n]%MOD*(i&1?MOD-1:1)%MOD;
		mul2();
		for(int x=0;x<=n;++x)
		for(int y=0;y<=m;++y)
			f[x][y]=1ll*f[x][y]*pw2[x*y]%MOD*fpow(pw3[x*y],MOD-2)%MOD;
	}
	int ans=1ll*f[n][m]*fac[n]%MOD*fac[m]%MOD;
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
  int a, b, c, n;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a >> b >> c;
    int tmp;
    if(a < b){
      tmp = a;
      a = b;
      b = tmp;
    }
    if(a < c){
      tmp = a;
      a = c;
      c = tmp;
    }
    (a * a == b * b + c * c) ? cout << "YES" << endl : cout << "NO" << endl;
  }
}

Measured memory_bytes: 1152
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
//#pragma GCC optimize(2)

int main(){
    int q,w,a[10],qwe;
    while(cin>>q>>w){
    if(q==1 && !w){
        cout<<0<<endl;
        continue;
    }
    for(int i=0;i<10;i++)a[i]=-1;
    qwe=0;
    for(int i=1;i<=w;i++){
        int s,d;
        cin>>s>>d;
        if(q!=1 && s==1 && d==0)
            qwe=1;
        else if(a[s]==-1)
            a[s]=d;
        else
            qwe=a[s]==d?0:1;
    }
    if(qwe){
        cout<<-1<<endl;
        continue;
    }
    string asd="";
    for(int i=1;i<=q;i++){
        if(a[i]==-1&&i==1)a[i]=1;
        else if(a[i]==-1)a[i]=0;
        asd+=a[i]+'0';
    }
    cout<<asd<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int max(int a , int  b){
  if(a > b) return a;
  else return b;

}
int min(int a , int b){
  if(a < b) return a;
  else return b;
}
bool cmp(pair < int , string >   a , pair < int , string >   b){
  if(a.first < b.first ) return true;
  else return false;
}
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int dp[105][100005];
int32_t main(){  
  fast;
  int n,ww;
  cin >> n >> ww;
  vector < int > w(n) , v(n);
  for(int i  = 0 ; i < n ; i++) cin >> w[i] >> v[i];
  dp[0][w[0]]=  v[0];
  for(int  i = w[0] ; i <= ww ; i++ ) dp[0][i] = v[0]; 
  for(int i = 1 ; i < n ; i++){
    for(int j = 0 ; j <=ww ;j++){
      if(w[i] <=j ) dp[i][j] = max(dp[i-1][j] , dp[i-1][j-w[i]]+v[i]);
      else dp[i][j] = dp[i-1][j];
    }
  }
  cout << dp[n-1][ww] << "\n";
  return 0;
} 

Measured memory_bytes: 80128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
const ll INF = 1000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int nax=105;
//const int nax1 = 105;

int main()
{
	FASTIO;
	int n;
	cin >> n;
	vector<int> arr(n);

	
	for(int i=0;i<n;i++){
			cin >> arr[i];
	}
	
	vector<int> dp(n, INF);
	dp[0]=0;
	
	for(int i=0;i<n;i++){
		for(int j=1;j<=2;j++){
			if(i+j <n)
				dp[i+j] = min(dp[i+j], dp[i]+abs(arr[i+j]-arr[i]));
		}
	}
	
	cout << dp[n-1] << "\n";
	

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
const int N=100001;
int n,b[N],p[N]={0},m,x,y,ans=0;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	FOR(i,0,N){p[i]=0;b[i]=1;}
	p[1]=1;
	cin>>n>>m;
	FOR(i,0,m){
		cin>>x>>y;
		b[x]--;
		b[y]++;
		if(p[x]==1){
			p[y]=1;
			if(b[x]==0){
				p[x]=0;
			}
		}
	}
	FOR(i,1,n+1){
		if(p[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,k;
            cin>>n;
            int ar[n+1],ans=0;
            for(i=1;i<=n;++i)
                cin>>ar[i];
            for(i=1;i<=n;++i)
            {
                for(j=i+1;j<=n;++j)
                {
                    if(ar[i]==ar[j])
                        continue;
                    for(k=j+1;k<=n;++k)
                    {
                        if(ar[i]==ar[k] || ar[j]==ar[k])
                            continue;
                        if(ar[i]+ar[j]>ar[k] && ar[i]+ar[k]>ar[j] && ar[j]+ar[k]>ar[i])
                        {
                            // cout<<i<<".."<<j<<".."<<k<<endl;
                            // cout<<ar[i]<<" "<<ar[j]<<" "<<ar[k]<<endl;
                            ++ans;
                        }
                    }
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
ll a[100010],x[100010],y[100010];
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll b;
		cin>>b;
		a[i]=b;
	}
	for(int i=0;i<n;i+=2){
		x[a[i]]++;
	}
	for(int i=1;i<n;i+=2){
		y[a[i]]++;
	}
	ll ans1=0,ans2=0;
	ll now1=0;
	for(int i=0;i<100010;i++){
		if(x[i]>ans1){
			ans2=ans1;
			ans1=x[i];
			now1=i;
			continue;
		}
		if(x[i]>ans2){
			ans2=x[i];
		}
	}
	ll ANS1=0,ANS2=0;
	ll NOW1=0;
	for(int i=0;i<100010;i++){
		if(y[i]>ANS1){
			ANS2=ANS1;
			ANS1=y[i];
			NOW1=i;
			continue;
		}
		if(y[i]>ANS2){
			ANS2=y[i];
		}
	}
	ll sum=0;
	if(now1==NOW1){
		sum=max(ans1+ANS2,ans2+ANS1);
		cout << n-sum;
		return 0;
	}
	cout << n -(ans1+ANS1);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
vector<pii> book[16];
int n;
int getbit(int x,int pos)
{
	int tmp=1<<(pos-1);
	if(x&tmp)return 1;
	else return 0;
}
bool check(int x)
{
	rep(i,0,n-1)
	{
		int tmp=1<<i;
		if(tmp&x)
		{
			for(auto xx:book[i+1])
			{
				if(xx.se!=getbit(x,xx.fi)) return false;
			}
		}
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	rep(i,1,n)
	{
		int a;
		cin>>a;
		rep(j,1,a)
		{
			int x,y;
			cin>>x>>y;
			book[i].pb({x,y});
		}
	}
	int ans=0,up=1<<n;
	rep(i,1,up-1)
	{
		int now=0,x=i;
		while(x)
		{
			if(x&1) now++;
			x>>=1;
		}
		if(check(i)) ans=max(ans,now);

	}
	cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 256
q, h, s, d = [int(x) for x in input().split()]
n = int(input())
per_l = min(4 * q, 2 * h, s)   # 1L買うのに一番安い方法
per_2l = min(2 * per_l, d) # 2Lを買うのに一番安い方法

print(per_2l * (n // 2) + per_l * (n % 2))

Measured memory_bytes: 2940
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    int op = 0;
    string s1 = "";
    string s2 = "";
    while (s1.length() != n)
    {
        int ok = 0;
        for (int a = 0;a < 2 && !ok;++a)
            for (int b = 0;b < 2 && !ok;++b)
            {
                char cnta = !a ? '.' : '#';
                char cntb = !b ? '.' : '#';
                string ns1 = (op ? s1 + cnta : cnta + s1);
                string ns2 = (op ? s2 + cntb : cntb + s2);
                fo << ns1 << '\n' << ns2 << '\n';
                fflush(stdout);
                char ans;
                fi>>ans;
                if (ans == 'T')
                {
                    ok = 1;
                    s1 = ns1;
                    s2 = ns2;
                }
            }
        op += !ok;
    }
    fo << s1 << '\n' << s2 << '\n';
    fflush(stdout);
    return 0;
}

Measured memory_bytes: 724