akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  while(true){
    const int m = getInt();
    const int t = getInt();
    const int p = getInt();
    const int r = getInt();

    if(m + t + p + r == 0) break;

    vector<vector<int> > memo(t, vector<int>(p));
    vector<pair<int, pair<int, int> > > ans(t);

    REP(i,t) ans[i].second.second = i + 1;

    REP(i,r){
      const int mm = getInt();
      const int tt = getInt() - 1;
      const int pp = getInt() - 1;
      const int jj = getInt();

      if(jj == 0){
        ans[tt].first        += 1;
        ans[tt].second.first -= memo[tt][pp] * 20 + mm;
      }else{
        memo[tt][pp]++;
      }
    }

    sort(ans.rbegin(), ans.rend());

    REP(i,t){
      const pair<int, pair<int, int> > now = ans[i];
      if(i != 0){
        const pair<int, pair<int, int> > prev = ans[i - 1];
        if(now.first == prev.first && now.second.first == prev.second.first)
          printf("=");
        else
          printf(",");
      }
      printf("%d", now.second.second);
    }
    puts("");
  }

  return 0;
}

Measured memory_bytes: 1076
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int five, seven, n;
  five = 2;
  seven = 1;
  for(int i = 0; i < 3; i++){
    scanf("%d", &n);
    if(n == 5) five--;
    if(n == 7) seven--;
  }
  if(five == 0 && seven == 0) printf("YES\n");
  else printf("NO\n");
  return 0;
}

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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}
//_____________________________________________________________________________\\

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        int n,k; cin>>n>>k; int a[n+5];
        for0(i,n) cin>>a[i];

        int dp[n+5]={};
        fill(dp,dp+n,1e9);
        dp[0]=0;

//        for1(i,k){ // this part doesn't work
//            for0(j,n){
//                if(j+i<n) dp[j+i]=min( dp[j+i], dp[j] + abs(a[j]-a[j+i]) );
//            }
//        }
//        forab(i, 0, n) cout<<dp[i]<<" "; cout<<endl;

        for0(j,n){ // starts from 0, covers all k then form 1, covers all k and so on
            for1(i,k){
                if(j+i<n) dp[j+i]=min( dp[j+i], dp[j] + abs(a[j]-a[j+i]) );
            }
        }
        //forab(i, 0, n) cout<<dp[i]<<" "; cout<<endl;
        cout<<dp[n-1];
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  bool f=1;
  for(int i=0;i<s.size();i++)
    if(s.at(i)==(i%2==0?'L':'R'))
      f=0;
  cout<<(f?"Yes":"No")<<endl;
}

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 300000;
const int mo = 998244353;

int fpm(int x, int y) {
    int res = 1;
    for(; y > 0; y >>= 1) {
        if(y & 1)
            res = (ll) res * x % mo;
        x = (ll) x * x % mo;
    }
    return res;
}

int fac[N + 5], inv[N + 5];
int binom(int n, int k) {
    return (ll) fac[n] * inv[k] % mo * inv[n - k] % mo;
}

ll n, a, b, k;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n), read(a), read(b), read(k);

    fac[0] = 1;
    for(int i = 1; i <= n; ++i) fac[i] = (ll) fac[i-1] * i % mo;
    inv[n] = fpm(fac[n], mo - 2);
    for(int i = n; i >= 1; --i) inv[i-1] = (ll) inv[i] * i % mo;

    ll ans = n * (a + b), res = 0;
    for(int i = 0; i <= n; ++i) if(ans - a * i >= k && (ans - a * i - k) % b == 0) {
        int j = (ans - a * i - k) / b;
        if(j <= n) res = (res + (ll) binom(n, i) * binom(n, j)) % mo;
    }
    printf("%lld\n", res);

    return 0;
}


Measured memory_bytes: 2560
import java.util.*;

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

		String str = sc.next();
		
		String decode = "";
		
		for(int i = 0; i < str.length(); i++) {
			if(str.charAt(i) == 'A') {
				decode+="X";
			} else if(str.charAt(i) == 'B') {
				decode+="Y";
			} else if(str.charAt(i) == 'C') {
				decode+="Z";
			} else {
				decode+=String.valueOf((char)(str.charAt(i) - 3));	
			}
		}
		
		System.out.println(decode);
	}
}

Measured memory_bytes: 30084
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int h[100010],c[100010];
int main(){
	int n,m,a,b,ans=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
		c[i]=0;
	}
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		if(h[a]>h[b]){
			c[b]=1;
		}
		else if(h[a]==h[b]){
			c[a]=1;c[b]=1;
		}
		else if(h[a]<h[b]){
			c[a]=1;
		}
	}
	for(int i=1;i<=n;i++){
		if(c[i]==0){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 4400
s_l = list(input())
n = len(s_l)
result = [1] *len(s_l)

# only for R
for i in range(n):
    if s_l[i] == 'L':
        continue
    if s_l[i+1] == 'L':
        continue
    else:
        result[i+2] += result[i]
        result[i] = 0

# only for L
for i in range(n):
    j = n-1 - i
    if s_l[j] == 'R':
        continue
    if s_l[j-1] == 'R':
        continue
    else:
        result[j-2] += result[j]
        result[j] = 0

print(' '.join(map(str,result)))

Measured memory_bytes: 11180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <map>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using lli = long long int;
using ll = long long;


int main() {
    lli N, K;
    cin >> N >> K;

    vector<lli> H(N);
    for (lli i = 0; i < N; ++i) {
        cin >> H[i];
    }

    sort(H.begin(), H.end());

    lli counter = 0;
    for (lli i = N - K - 1; i >= 0; --i) {
        counter += H[i];
    }

    cout << counter << endl;
}


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

int main(){
  char S[500001];
  int f=0,l;
  scanf("%s",S);
  l = strlen(S);
  int odd=0,even=0;
  for(int i=0;i<l;i++){
    if(i&1){	/*odd*/
      if(S[i]&1){
        odd++;
      }
      else{
        even++;
      }
    }
    else{		/*even*/
      if(S[i]&1){
        even++;
      }
      else{
        odd++;
      }
    }
  }
  if(odd<even){
    printf("%d\n",odd);
  }
  else{
    printf("%d\n",even);
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  bool f=1;
  int ans=0;
  while (f) {
    f=0;
    for (int j=N-1; j>=1; j--) {
      if (A[j]<A[j-1]) {
        int v=A[j-1];
        A[j-1]=A[j];
        A[j]=v;
        ans++;
        f=1;
      }
    }
  }
  for (int i=0; i<N; i++) {
    cout << (i==0?"":" ") << A[i] << flush;
  }
  printf("\n");
  printf("%d\n",ans);
  return 0;
}

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

int a[200000];
int n,i;
void init()
{
    cin >> n;
	for (i=0; i<n; i++)
    {
		cin >> a[i];
	}
}
int main()
{
    init();
	for (i=n-1; i>=0; i-=2)
    {
		cout << a[i] << " ";
	}
	i++;
	if (n % 2) i += 2;
	for (; i<=n-2; i+=2)
	{
        cout << a[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
const int maxn=10005;
long long res,ada,adb;
int n;
long long a[maxn],b[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i=0;i<n;++i)
        cin>>a[i];
    for (int i=0;i<n;++i)
        cin>>b[i];
    for (int i=0;i<n;++i) {
        long long now=(b[i]>a[i])?b[i]+((b[i]-a[i])&1):a[i];
        ada+=max(0LL,(now-a[i])/2);
        adb+=max(0LL,now-b[i]);
    }
    if (ada<adb) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader stdReader =
        new BufferedReader(new InputStreamReader(System.in));
      String line;
      while ((line = stdReader.readLine()) != null) { 
    	  int x = Integer.parseInt(line);
        System.out.println(x*x*x);
      }
      stdReader.close();
    } catch (Exception e) {
      e.getStackTrace();
      /*?????´??????0??????*/
      System.exit(0); 
    }
  }
}

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

int main(){

    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    int ans = 1e8;
    ans = min(ans, abs(A1 - A2) + abs(A2 - A3));
    ans = min(ans, abs(A1 - A3) + abs(A3 - A2));
    ans = min(ans, abs(A2 - A1) + abs(A1 - A3));
    ans = min(ans, abs(A2 - A3) + abs(A3 - A1));
    ans = min(ans, abs(A3 - A1) + abs(A1 - A2));
    ans = min(ans, abs(A3 - A2) + abs(A2 - A1));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
function main()
  
  (H,W) = map(x -> parse(Int,x), split(readline()))
  
  a = ["" for i in 1:H,j in 1:W]
  
  check_H = zeros(Int,H)
  check_W = zeros(Int,W)
  
  for i in 1:H
      a[i,:] = split(chomp(readline()),"")
  end
  
  count = 0
  
  for i in 1:H
    
      for j in 1:W
          if a[i,j] == "."
              count += 1
          end
      end
    
      if count == W
          check_H[i] = 1
          count = 0
      else
          count = 0
      end
    
  end

  for i in 1:W
    
      for j in 1:H
          if a[j,i] == "."
              count += 1
          end
      end
    
      if count == H
          check_W[i] = 1
          count = 0
      else
          count = 0
      end

  end
  
  for i in 1:H
    
      if check_H[i] == 1
          continue
      end
    
      for j in 1:W
          if check_W[j] == 1
              continue
          else
              print(a[i,j])
          end
      end
    
      println()
  
  end
  
end

main()

Measured memory_bytes: 173476
#include <iostream>

using namespace std;

int main(void)
{
    int a, b, c;

    cin >> a >> b >> c;
    int k;
    cin >> k;

    int max = 0;
    if(a > max)
        max = a;
    if(b > max)
        max = b;
    if(c > max)
        max = c;

    int sum = a + b + c - max;
    for(int i = 0; i < k; i++){
        max *= 2;
    }
    sum += max;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (){

  int i,j,H,W;
 

  while(1){

    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0)break;

    for(i = 0;i < H; i++){

      for(j = 0;j < W;j++){	
	if (i % 2 == 0){
	  if (j % 2 == 0) printf("#");
	  else printf(".");		    
	}
	else {
	  if (j % 2 == 1) printf("#");
	  else printf(".");
	}
      }
      printf("\n");
	
      }
    printf("\n");
  }
  
  

  return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }

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

    int n, m; cin >> n >> m;
    vel x(n), y(m); rep(i,n) cin >> x[i]; rep(i,m) cin >> y[i];

    ll ans1 = 0LL; ll ans2 = 0LL;
    for(int i = 0; i <= n-1; i++) { ans1 += (2 * i - n + 1) * x[i]; ans1 %= mod; }
    for(int i = 0; i <= m-1; i++) { ans2 += (2 * i - m + 1) * y[i]; ans2 %= mod; }
    ll ans = ans1 * ans2;
    ans %= mod;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;
public class Main {
    /**
     * @param args
     */
/**
 * @author shirai_a
 *
 */
    /**
     * @param args
     */
    public static void main(String[] args) {
        ArrayList<Double> intlist = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        sc.nextLine();
        for (String str: sc.nextLine().split(" ")){
            intlist.add(Double.parseDouble(str));
          }
            sc.close();
        Collections.sort(intlist);
        double tr = intlist.get(0);
        for(int i = 1; i < intlist.size(); i++) {
            tr = (tr + intlist.get(i))/2;
        }
        System.out.println(tr);
    }
}



Measured memory_bytes: 21844
def count(x1,y1,x2,y2):
  ret=acum[y2][x2]
  if x1!=0:
    ret-=acum[y2][x1-1]
  if y1!=0:
    ret-=acum[y1-1][x2]
  if x1!=0 and y1!=0:
    ret+=acum[y1-1][x1-1]
  return ret

h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
acum=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if board[i][j]=='1':
      acum[i][j]+=1
    if i!=0:
      acum[i][j]+=acum[i-1][j]
    if j!=0:
      acum[i][j]+=acum[i][j-1]
    if i!=0 and j!=0:
      acum[i][j]-=acum[i-1][j-1]
ans=10**18
for rows in range(2**(h-1)):
  hlist=[]
  flag=format(rows,'b')[::-1]
  for i in range(len(flag)):
    if flag[i]=='1':
      hlist.append(i)
  hlist.append(h-1)
  cnt=len(hlist)-1
  x1=0
  for x2 in range(w-1):
    y1=0
    for y2 in hlist:
      if count(x1,y1,x2,y2)>k:
        cnt+=10**18
      if count(x1,y1,x2,y2)<=k and count(x1,y1,x2+1,y2)>k:
        cnt+=1
        x1=x2+1
        break
      y1=y2+1
  y1=0
  for y2 in hlist:
    if count(x1,y1,w-1,y2)>k:
      cnt+=10**18
    y1=y2+1
  ans=min(ans,cnt)
print(ans)

Measured memory_bytes: 50396
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;
const int MAXN = 100000;
int SendQuery(int n);

struct _query
{
    int result;
    int query;
    _query(){};
    _query(int qu)
    {
        result = SendQuery(qu);
        query = qu;
    }
};

string str;

int N;

int SendQuery(int n)
{
    cout << n << endl << flush ;

    cin >> str ;
    if(str == "Vacant")
        exit(0);
    if(str == "Male")
        return 0;
    return 1;
}

int getExpAns(int curpos, _query prevQuery)
{
    if((curpos - prevQuery.query) & 1)
        return !(prevQuery.result);
    return prevQuery.result;
}

void binaryQuery()
{
    int l = 0, r = N;

    _query leftQuery, rightQuery;
    leftQuery.query = 0, leftQuery.result = SendQuery(0);
    rightQuery.query = N-1, rightQuery.result = SendQuery(N-1);

    while(r-l > 1)      // [l, r)
    {
        int mid = (l+r) >> 1;
        //cerr << "Expected Answer :" << getExpAns(mid, leftQuery) << endl ;
        _query MidQuery(mid);
        if(MidQuery.result == getExpAns(mid, leftQuery))
        {
            l = mid;
            leftQuery = MidQuery;
        }
        else
        {
            r = mid;
            rightQuery = MidQuery;
        }

    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> N;
    binaryQuery();
    return 0;
}


Measured memory_bytes: 852
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(N)]
dic = {}
for a, b in ab:
    dic[(a, b)] = 0
for c, d in cd:
    dic[(c, d)] = 0

ab = sorted(ab, key=lambda x: (-x[0], -x[1]))
cd = sorted(cd, key=lambda x: (x[1], x[0]))

ans = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d and dic[(a, b)] == 0 and dic[(c, d)] == 0:
            ans += 1
            dic[(a, b)] += 1
            dic[(c, d)] += 1
print(ans)

Measured memory_bytes: 70356
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;

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

int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    vector<int> L(N), R(N);
    L.front() = A.front(), R.back() = A.back();
    for(int i = 1; i < N; i++){
        L[i] = gcd(L[i - 1], A[i]);
        R[N - i - 1] = gcd(R[N - i], A[N - i - 1]);
    }

    int64_t ans = max(L[N - 2], R[1]);
    for(int i = 1; i < N - 1; i++){
        ans = max(ans, gcd(L[i - 1], R[i + 1]));
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    //入力
    int n;
    cin >> n;
    int ans=0;
    int r;
    for(int i=0;i<n;i++)
    {
        cin >> r;
        ans+=r;
    }
    cout << ans-n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define inf 100000
#define NIL -10

void prim();

int G[101][101],n;

int main()
{
  int i,j,m;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&m);
      if(m==-1) G[i][j] = inf;
      else G[i][j] = m;
    }
  }

  prim();
  
  return 0;
}

void prim()
{
  int i,min,u,v,sum=0;
  int d[101],pi[101],c[101];
  
  for(i=0;i<n;i++){
    d[i] = inf;
    pi[i] = NIL;
    c[i] = 0;
  }

  d[0] = 0;

  while(1){
    min = inf;
    u = NIL;
    for(i=0;i<n;i++){
      if(c[i]!=2 && d[i]<min){
	min = d[i];
	u = i;
      }
    }
    if(u==NIL) break;
    c[u] = 2;
    for(v=0;v<n;v++){
      if(c[v]!=2 && G[u][v]!=inf){
	if(d[v]>G[u][v]){
	  d[v] = G[u][v];
	  pi[v] = u;
	  c[v] = 1;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(pi[i]!=NIL) sum += G[i][pi[i]];
  }
  printf("%d\n",sum);
}



  
  
  

  
  



Measured memory_bytes: 2052
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a = str(input())
dic = {"A": "T", "T": "A", "C": "G", "G": "C"}
print(dic[a])


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

int main()
{ 
  int n ;
  cin >> n ;
  set<char> data ;
  for(int i = 0 ; i < n ; i++)
  {
    char x ;
    cin >> x ;
    data.insert(x) ;
  }

  if (data.size() == 3)
  {
    cout << "Three" << endl ;
  }
  else if(data.size() == 4)
  {
    cout << "Four" << endl ;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long
using namespace std;
ll n,a,b; 
int main(){
	cin>>n>>a>>b;
	if((a&1)==(b&1)) printf("%lld",abs(a-b)/2);
	else printf("%lld",min((a+b-1)/2,(2*n-a-b+1)/2));
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 200005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define sq(x) ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

i64 a[maxn] ;

int main()
{
    i64 i , j , k , l ,m , n ;

    scanf("%lld",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    a[0] = -1 ;

    for(i=1 ; i<=n ; i++)
    {
        if( a[i]-a[i-1] > 1 )
        {
            printf("-1\n") ;
            return 0 ;
        }
    }

    i64 ans = 0LL ;

    for(i=2 ; i<=n ; i++)
    {
        if( a[i]-a[i-1] == 1 ) ans++ ;
        else ans += a[i] ;
    }

    cout<<ans<<endl ;

    return 0 ;
}


Measured memory_bytes: 1792
#include<stdio.h>
  
int main(){
    int dice[6],q,i;
    char c;
      
    for(i=0;i<6;i++){
        scanf("%d",&dice[i]);
    }
      
    scanf("%d",&q);
    for(i=0;i<q;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if((x==dice[5] && y==dice[4])||(x==dice[4] && y==dice[0])||(x==dice[0] && y==dice[1])||(x==dice[1] && y==dice[5])){
            printf("%d\n",dice[2]);
        }else if((x==dice[0] && y==dice[2])||(x==dice[2] && y==dice[5])||(x==dice[5] && y==dice[3])||(x==dice[3] && y==dice[0])){
            printf("%d\n",dice[4]);
        }else if((x==dice[5] && y==dice[1])||(x==dice[1] && y==dice[0])||(x==dice[0] && y==dice[4])||(x==dice[4] && y==dice[5])){
            printf("%d\n",dice[3]);
        }else if((x==dice[0] && y==dice[3])||(x==dice[3] && y==dice[5])||(x==dice[5] && y==dice[2])||(x==dice[2] && y==dice[0])){
            printf("%d\n",dice[1]);
        }else if((x==dice[2] && y==dice[1])||(x==dice[1] && y==dice[3])||(x==dice[3] && y==dice[4])||(x==dice[4] && y==dice[2])){
            printf("%d\n",dice[5]);
        }else{
            printf("%d\n",dice[0]);
        }
    }
    return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin>>n;
	long long l[101];
	long ans=0; 
	for(int i=0;i<n;i++)
	{
		cin>>l[i]; 
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				if(l[i]!=l[j] && l[i]!=l[k] && l[j]!=l[k] && l[i]+l[j]>l[k] && l[i]+l[k]>l[j] && l[k]+l[j]>l[i])
				ans++;
			} 
		} 
	}
	ans/=6;
	cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include<stdio.h>

int main(){
    char word1[1000], word2[1000],temp1,temp2;
    scanf("%s", word1);
    scanf("%s", word2);
    int len=0;
    for (int i=0;word1[i]!='\0';i++){
        len++;
    }
    for (int j=0;j<len;j++){
        for (int i=len-1;i>=0;i--){
            word1[i+1]=word1[i];
        }
        word1[0]=word1[len];
        int flag=0;
        for (int k=0;k<len;k++){
            if (word1[k]!=word2[k]){
            flag=1;
            }
        }
        if (flag==0){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}




Measured memory_bytes: 128
import java.util.Scanner;
import java.util.stream.LongStream;

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

        long ans = LongStream.rangeClosed(1, N)
                .filter(x -> x % 3 != 0)
                .filter(x -> x % 5 != 0)
                .sum();

        System.out.println(ans);

    }

}


Measured memory_bytes: 36768
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
#print(L)
ans = 0

"""
これだとTLEしてしまう
for i in range(N-2):
    for j in range(i+1, N-1):
        left = j
        right = N
        target = L[i]-L[j]
        while right-left > 1:
            mid = (right + left)//2
            #print(mid)

            if L[mid] > target:
                left = mid
            else:
                right = mid

        ans += left-j
        """

L.sort()
for i in range(N):
    for j in range(i+1, N):
        target = L[i]+L[j]
        left = bisect_left(L, target) #二分探索の関数
        ans += max(0, left-j-1)


print(ans)


Measured memory_bytes: 9192
import java.util.*;

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();
        System.out.println(Math.max(A*B,C*D));
    }
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,p,memo,ans;

main() {
    cin >> n;
    rep1(i,n) {
        cin >> p;
        if (p == i) {
            if (memo) memo = 0,ans++;
            else memo = 1;
        } else if (memo) memo = 0,ans++;
    }
    if (memo) ans++;
    cout << ans << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int inf=1e5+8;
int A[inf];
int n;
int dp[inf];

int f(int index){
     if(index==n-1) return 0;
     if(index==n-2) return abs(A[index]-A[index+1]);
     int&ans=dp[index];
     if(dp[index]!=-1) return ans;

     ans=INT_MAX;
     ans=min(ans, abs(A[index]-A[index+1])+f(index+1));
     ans=min(ans, abs(A[index]-A[index+2])+f(index+2));
     return ans;
}

int main(){
     memset(dp, -1, sizeof(dp));
     cin>>n;
     for(int i=0;i<n;i++)cin>>A[i];
     cout<<f(0);
}


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

int cnt[100];
int N, K;
int main() {
  cin >> N >> K;
  for(int i = 0; i < K; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    cnt[a]++;
    cnt[b]++;
  }
  for(int i = 0; i < N; ++i) {
    cout << cnt[i] << endl;
  }
}


Measured memory_bytes: 256
// Problem : A - We Love Golf
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

ll a,b,n;

ll test(ll x){
	return a*x/b-a*(x/b);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>a>>b>>n;
	
	//for (int x=1;x<=n;x++) cout<<x<<" "<<test(x)<<endl;
	
	cout<<test(min(n,b-1));
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


int n, m;
char c[55][55], d[55][55];
signed main() {
	cin >> n >> m;
	rep(i, n)rep(j, n)cin >> c[i][j];
	rep(i, m)rep(j, m)cin >> d[i][j];
	rep(i, n - m + 1) {
		rep(j, n - m + 1) {
			rep(k, m)rep(l, m) {
				if (d[k][l] != c[k + i][l + j])goto ng;
			}
			cout << "Yes" << endl; return 0;
		ng:;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, k, x, y, sum = 0;
    scanf("%d%d%d%d", &n, &k, &x, &y);
    sum += n * x;
    if(n > k) sum -= (n - k) * (x - y);
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    ll a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    ll ans_total = 0;
    ll ans_sato = 0;
    double ans_noudo = 0;
    rep(i,30){
        ll water = 100*i;
        if(water>f){
            break;
        }
        bool water_flag =false;
        rep(j,30){
            rep(k,15){
                if(j*a+k*b==i){
                    water_flag = true;
                    break;
                }
            }
        }
        if(!water_flag){
            continue;
        }
        rep(alpha,3000){
            if(i*e-alpha*c < 0 || f-water-alpha*c < 0){
                break;
            }
            ll beta = min((i*e-alpha*c)/d, (f-water-alpha*c)/d);
            ll sato = alpha*c+beta*d;
            double noudo = (double)sato / (sato + water);
            if(ans_noudo <= noudo){
                ans_noudo = noudo;
                ans_total = sato+water;
                ans_sato = sato;
            }
        }
    }
    cout << ans_total << " " << ans_sato;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
int cnt[300000];

bool is_prime[300000];

int sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = 1;
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = 0;
		}
	}
	return p;
}

int main() {
	sieve(300000 - 1);
	FOR(i, 1, 300000) {
		cnt[i] = cnt[i - 1] + is_prime[i];
	}
	while (cin >> n &&n) {
		cout << cnt[2 * n] - cnt[n] << endl;
	}
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
  
signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s;
    cin >> s;
    if(s.back() == 's') {
    	cout << (s + "es"); 
    } else {
    	cout << (s + "s");
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int sum;
  int count = 0;
  for(int i = 0; i <= 25; i++){
    for(int j = 0;j <= 15;j++){
      sum = 4*i + 7*j;
      if(sum == N){
        count++;
      }
    }
  }
  if(count == 0){
    cout << "No" << endl;
  }
  if(count >= 1){
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int N;
    cin >> N;
    deque<int> a(N);
    int tmp;
    int alice = 0;
    int bob = 0;
    REP(i, N) {
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end(), greater<int>());
    while(!a.empty()) {
        alice += a.front();
        a.pop_front();
        if(!a.empty()) {
            bob += a.front();
            a.pop_front();
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define fio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 4005;
string a,b;
int n;

int pl[N],pr[N];
int pfl[N],pfr[N];

vector<pii> v;

int main() {
	fio;
	cin >> a >> b;
	if(a==b) {
		printf("0\n");
		return 0;
	}
	n = a.size();
	int last = -1;
	for(int i = 0; i < 2*n; ++i) {
		if(b[i%n] == '1')
			last = i;
		if(i >= n)
			pl[i-n] = i-last;
	}
	if(last == -1) {
		printf("-1\n");
		return 0;
	}
	last = 2*n;
	for(int i = 2*n-1; i >= 0; --i) {
		if(b[i%n] == '1')
			last = i;
		if(i < n)
			pr[i] = last-i;
	}

	int ans = 1<<26;
	for(int s = 1-n; s < n; ++s) {
		string c = a;
		for(int i = 0; i < n; ++i) {
			int j = (i+s+n)%n;
			c[i] = a[j];
		}
		v.clear();
		for(int i = 0; i < n; ++i) {
			if(c[i] != b[i]) {
				v.emplace_back(pl[i],pr[i]);
			}
		}
		int base_l=0,base_r=0;
		if(s < 0) base_l = -s;
		if(s > 0) base_r = s;
		sort(v.begin(),v.end());
		pfl[0] = pfr[0] = 0;
		for(int i = 1; i <= v.size(); ++i) {
			pfl[i] = max(pfl[i-1],v[i-1].fi);
			pfr[i] = max(pfr[i-1],v[v.size()-i].se);

		}

		//iter on max l
		for(int i = 0; i <= v.size(); ++i) {
			int max_l = pfl[i], max_r = pfr[v.size()-i];
			int r = v.size();
			r += 2*(max(base_r,max_r) - base_r);
			r += base_r;
			r += 2*(max(base_l,max_l) - base_l);
			r += base_l;
			ans = min(ans,r);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 384
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int n = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(sc.next());
        }
        System.out.println(set.size());
    }
}


Measured memory_bytes: 78384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-7;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");

long long a[3010][3010];
long long dp[3010][3010][4];

void solve()
{
	int r, c;
	cin >> r >> c;
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		int r1, c1, v;
		cin >> r1 >> c1 >> v;
		a[r1 - 1][c1 - 1] = v;
	}
	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			if (!a[i][j])
			{
				dp[i][j + 1][0] = max({ dp[i][j + 1][0], dp[i][j][0] });
				dp[i][j + 1][1] = max({ dp[i][j + 1][1], dp[i][j][1] });
				dp[i][j + 1][2] = max({ dp[i][j + 1][2], dp[i][j][2] });
				dp[i][j + 1][3] = max({ dp[i][j + 1][3], dp[i][j][3] });
				dp[i + 1][j][0] = max({ dp[i + 1][j][0], dp[i][j][0], dp[i][j][1], dp[i][j][2], dp[i][j][3] });
			}
			else
			{
				dp[i][j + 1][0] = max({ dp[i][j + 1][0], dp[i][j][0] });
				dp[i][j + 1][1] = max({ dp[i][j + 1][1], dp[i][j][1], dp[i][j][0]  + a[i][j] });
				dp[i][j + 1][2] = max({ dp[i][j + 1][2], dp[i][j][2], dp[i][j][1]  + a[i][j] });
				dp[i][j + 1][3] = max({ dp[i][j + 1][3], dp[i][j][3], dp[i][j][2]  + a[i][j] });

				dp[i + 1][j][0] = max({ dp[i + 1][j][0], dp[i][j][0], dp[i][j][1], dp[i][j][2], dp[i][j][3] });
				dp[i + 1][j][0] = max({ dp[i + 1][j][0], dp[i][j][0] + a[i][j], dp[i][j][1] + a[i][j], dp[i][j][2] + a[i][j]});
			}
		}
	}
	cout << dp[r][c - 1][0];
}

int main()
{
	cout << setprecision(2) << fixed;
	cin.tie();
	cout.tie();
	//freopen("input.txt", "r", stdin);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	gg;
}

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

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;		
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b) 
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	int n;
	cin >> n;
	vector<list<pair<int, bool>>> w(n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		ll we;
		cin >> u >> v >> we;
		u--;
		v--;
		w[u].push_back(make_pair(v, we % 2 == 0));
		w[v].push_back(make_pair(u, we % 2 == 0));
	}

	vector<int> use(n, -1);
	queue<int> q;

	for (int i = 0; i < n; i++)
	{
		if (use[i] >= 0)
			continue;
		use[i] = 0;
		for (auto it : w[i])
		{
			if (use[it.first] >= 0)
				continue;
			use[it.first] = it.second ? 0 : 1;
			q.push(it.first);
		}

		while (!q.empty())
		{
			for (auto it : w[q.front()])
			{
				if (use[it.first] >= 0)
					continue;
				if (use[q.front()] == 0)
					use[it.first] = it.second ? 0 : 1;
				else
					use[it.first] = it.second ? 1 : 0;
				q.push(it.first);
			}
			q.pop();
		}
	}

	for (int i = 0; i < n; i++)
		printf("%d\n", use[i]);

	return 0;
}


Measured memory_bytes: 9472
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string retValue = "Good";

        string S = Console.ReadLine();

        string oldS = string.Empty;
        string newS = string.Empty;

        for (int i = 0; i < 4; i++)
        {
            newS = S.Substring(i, 1);

            if (oldS == newS)
            {
                retValue = "Bad";
                break;
            }

            oldS = newS;
        }

        //出力
        Console.WriteLine(retValue);
    }
}

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

using namespace std;

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

  tmp=s+s;
  if (tmp.find(t)!=string::npos) 
      cout << "Yes" << endl;
  else
      cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const ll INF = 1e17+7;


int main(){

    int n,z,w;
    cin >> n >> z >> w; 
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    int ans = 0;
    if(n == 1){
        ans = abs(a[n-1] - w);
    }else{
        ans = max(abs(a[n-1]-w),abs(a[n-1]-a[n-2]));
    }
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    // i -> 水の量, j -> 砂糖の量
    double max_melt = -1.0;
    int water, sugar;
    for(int i = 0; i <= f; i += 100 * a){
        for(int j = 0; j <= f - i; j += 100 * b){
            for(int k = 0; k <= f - i - j; k += c){
                for(int l = 0; l <= f - i - j - k; l += d){
                    if((k + l) * 100 <= e * (i + j)){
                        double per = 100.0 * (k + l) / (i + j + k + l);
                        if(max_melt < per){
                            water = i + j;
                            sugar = k + l;
                            max_melt = per;
                        }
                    }
                }
            }
        }
    }

    cout << water + sugar << " " << sugar << endl;
}

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

using namespace std;

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

  int n;
  cin >> n;
  int sum = 0;
  set<int> s;
  for (int i = 0; i < n; ++i) {
    int score;
    cin >> score;
    s.insert(score);
    sum += score;
  }
  if (sum % 10 != 0) {
    cout << sum << "\n";
    return 0;
  }
  for (auto& e : s) {
    if (e % 10 == 0) continue;
    cout << sum - e << "\n";
    return 0;
  }
  cout << "0\n";
}


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

int N, X, Y;

void solve(){
    map<int, int> ans;
    for(int i = 1; i <= N - 1; ++i){
        ans[i] = N - i;
    }
    for(int i = 1; i <= N; ++i){
        for(int j = i + 1; j <= N; ++j){
            if(i == j) continue;
            int dist = min(abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X));
            if(dist < j - i) {
                ans[j - i]--;
                ans[dist]++;
            }
        }
    }
    for(int i = 1; i <= N - 1; ++i){
        cout << ans[i] << endl;
    }
}
int main(){
    cin >> N >> X >> Y;
    solve();
    return 0;
}

Measured memory_bytes: 384
n, m = map(int, input().split())

a = []

for i in range(m):
    p, y = map(int, input().split())
    a.append([p, y, i])

a = sorted(a)

num = 1
for i in range(m - 1):
    if a[i][0] != a[i + 1][0]:
        a[i].append(num)
        num = 1
    else:
        a[i].append(num)
        num += 1

a[-1].append(num)

# 元の市の順に戻す
a = sorted(a, key=lambda x: x[2])
for i in range(m):
    first = str(a[i][0])
    second = str(a[i][3])
    print(first.zfill(6) + second.zfill(6))



Measured memory_bytes: 31788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
	int n, a, b, cnt=0;
	cin >> n;
	vector<int> p(n), q(n), s(n);
	rep(i,n) s[i] = i+1;
	rep(i,n) cin >> p[i];
	rep(i,n) cin >> q[i];

	do {
		cnt++;
		if (s == p) a = cnt;
		if (s == q) b = cnt;
	} while (next_permutation(s.begin(), s.end()));
	cout << max(a-b, b-a);
	return 0;
}

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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,r,n) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

using ll = long long int;
using ull = unsigned long long int;
using vi = vector<ll>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> n >> k;
	if (n < 10 && k < 10)
    cout << n * k << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m;
int main(void){
    // Your code here!
    cin >> n >> m;
    if (n == 1 || m == 1) {
        cout << (n == m ? 1 : n * m - 2) << endl;
    } else {
        cout << (n - 2) * (m - 2) << endl;
    }
}


Measured memory_bytes: 256